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
13创库和授权
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';