一:數據庫(mysql)
1 備份命令
# mysqldump -uroot -pDbb790827253+ -h192.168.0.180 --all-databases --single_transaction --flush-log --master-data=2 --lock-tables > /data/mysqlbackup.sql
導入
#mysql -uzabbix -p123456 -h172.20.100.3 zabbix< database/mysql/schema.sql
2 創建庫和用戶命令創建庫
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@"%" identified by '123456';
3 主從命令
mysql> GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'rsync-user'@'172.20.100.%' IDENTIFIED BY '123456';mysql> CHANGE MASTER TO MASTER_HOST='172.20.100.3',MASTER_USER='rsyncuser',MASTER_PASSWORD='123456',MASTER_LOG_FILE='bin-log.xxxxxx',MASTER_LOG_POS=xxx;
4 查詢語句
mysql> show variables like '%connect%';
mysql> show variables like '%max_connections%';
mysql> desc notice_config;
mysql> show master logs;
查看連接數
mysql> show processlist;
mysql> show processlist \\G;
5 查詢mysql的日誌問題
# memory
6查看用戶和密碼 修改密碼查看到用戶和密碼
MySQL [(none)]> select host,user,password from mysql.user;
如果要修改密碼的話,在命令行下執行下面的語句
update mysql.user set password='這裡填寫你要設置的密碼' where user='root';
update user set password=password('123456') where user='root' and host='localhost';
7查看數據庫的配置在裡面
mysql> show variables like 'pxc_strict_mode%';
8 修改數據庫密碼
安裝完數據庫第一次設置密碼方式 輸完命令按回車,不用在下面輸入。
#mysqladmin -u root -p password 123456
Enter password:
其設置密碼有三種方法:
a. ./mysqladmin -u root -p oldpassword newpasswd(記住這個命令是在/usr/local/mysql/bin中外部命令)
b. SET PASSWORD FOR root=PASSWORD(’new password’);(對登錄數據庫後這種方式)
c. UPDATE user SET password=PASSWORD(”new password”) WHERE user=’root’; (對登錄數據庫後這種方式)
生效
mysql> flush privileges;
數據庫sql語句
查詢數據庫表的大小
SELECT table_name AS "Tables",
round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB"
FROM information_schema.TABLES
WHERE table_schema = 'zabbix'
ORDER BY (data_length + index_length) DESC;
9 增加root遠程權限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';
flush privileges;
10:#skip-grant-tables 無視密碼登錄
11:安裝mariadb數據庫
#yum -y install mariadb mariadb-server
#systemctl start mariadb
#systemctl enable mariadb
接下來進行MariaDB的相關簡單配置,設置密碼,會提示先輸入密碼
[root@test-vm03 ~]# mysql_secure_installation
首先是設置密碼,會提示先輸入密碼
Enter current password for root (enter for none):
設置密碼
Set root password? [Y/n]
New password:
Re-enter new password:
其他配置
Remove anonymous users? [Y/n]
Disallow root login remotely? [Y/n]
Remove test database and access to it? [Y/n]
Reload privilege tables now? [Y/n]
12 配置MariaDB的字符集
接下來配置MariaDB的字符集:
-> 首先是配置文件/etc/my.cnf,在[mysqld]標籤下添加
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
-> 接著配置文件/etc/my.cnf.d/client.cnf,在[client]中添加
default-character-set=utf8
-> 然後配置文件/etc/my.cnf.d/mysql-clients.cnf,在[mysql]中添加
default-character-set=utf8
mysql數據庫
create database zabbix default character set utf8 collate utf8_bin;
grant all on zabbix.* to 'zabbix'@'%' identified by '123456';
flush privileges;
14:修改最大連接數
MYSQL修改最大連接數
方法一:
set GLOBAL max_connections=512;
這種方法在重啟服務後會失效
方法二:
修改mysql配置文件my.cnf,在[mysqld]段中添加或修改max_connections值:
max_connections=512
MariaDB修改最大連接數
1.mariadb數據庫最大連接數,默認為151
MariaDB [(none)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 151 |
+-----------------+-------+
2.配置/etc/my.cnf
[mysqld]下新添加一行如下參數:
max_connections=3000
systemctl restart mariadb 重啟mariadb服務,再次查看mariadb數據庫最大連接數,最大連接數是214,並非我們設置的3000。
MariaDB [(none)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 214 |
+-----------------+-------+
由於mariadb有默認打開文件數限制
vi /usr/lib/systemd/system/mariadb.service
取消[Service]前的#號,
[Service]新添加兩行如下參數:
LimitNOFILE=10000
LimitNPROC=10000
4.重新加載系統服務,並重啟mariadb服務
systemctl --system daemon-reload
systemctl restart mariadb.service
再次查看mariadb數據庫最大連接數,可以看到最大連接數已經是3000
MariaDB [(none)]> show variables like 'max_connections';