MySql主从复制配置,你了解吗?来看这篇,全懂了( 三 )
执行示意
[root@pmondbs01 ~]# service mysqld start
[root@pmondbs01 ~]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
2. 查询root账号临时密码
检索在MySQL数据文件目录的mysql-error.log文件可以查找到密码,密码检索关键字为“password”,关键字“password”所在行“A temporary password is generated for root@localhost:”后面为临时密码,比如“swf88nhHgx(z”为临时密码 。该临时密码作为第一次使用root账号登录数据库使用的密码 。
注:MySQLroot账号的临时密码是随机生成的每次安装都会产生不同的密码 。
mysql-error.log位于/data/下 。
使用命令
执行顺序
命令
说明
1
cat /data/mysql-error.log|grep password
读取mysql-error.log并过滤关键password
2
2020-01-08T15:48:42.569059+08:00 1 [Note] A temporary password is generated for root@localhost: swf88nhHgx(z
输出
执行示意
[root@pmondbs01 ~]# cat /data/mysql-error.log|grep password
2020-01-08T15:48:42.569059+08:00 1 [Note] A temporary password is generated for root@localhost: swf88nhHgx(z
3. 修改root账号密码
登录MySQL数据库,修改root账号密码为password,创建可以从任何主机访问数据库的root账号并设置密码为password,用于管理数据库;创建可以从任何主机访问数据库的同步账号repl并设置密码为repl,用于MySQL数据库主从同步,并给账号赋予相应权限 。
登录MySQL数据库命令为mysql -uroot -p,回车之后输入密码,密码为上一步操作查询到的临时密码swf88nhHgx(z 。
创建root账号并设置密码为password的SQL语句为:“create user root@'%' identified by 'password';”
授权root账号具有所有权限的SQL语句为grant all privileges on *.* to root@'%';
修改root账号密码为password的SQL语句为alter user root@localhost identified by 'password';
使用命令
执行顺序
命令
说明
1
cd /usr/local/mysql/bin
进入MySQL安装目录的bin目录下
2
./mysql -uroot -p
启动MySQL客户端
3
swf88nhHgx(z
输入root账号密码,进入MySQL命令行客户端 。root账号密码在上一步骤中获取 。
4
alter user root@localhost identified by 'password';
修改root账号密码为password
5
create user root@'%' identified by 'password';
创建可以从任何主机访问数据库的root账号并设置密码为password
6
grant all privileges on *.* to root@'%';
授权可以从任何主机访问数据库的root账号所有权限
7
flush privileges;
刷新数据库权限
12
flush privileges;
刷新数据库权限
13
create user repl@'%' identified by 'repl';
创建可以从任何主机访问数据库的repl账号并设置密码为reple
14
grant replication slave on *.* to 'repl'@'%';
授权可以从任何主机访问数据库的repl账号replication slave权限
15
flush privileges;
刷新数据库权限
16
quit;
退出MySQL命令行客户端
执行示意
[root@localhost ~]# cd /usr/local/mysql/bin
[root@pmondbs01 bin]# ./mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.7.22-log
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MySQL [(none)]>alter user root@localhost identified by 'password';
Query OK, 0 rows affected (0.02 sec)
MySQL [(none)]> create user root@'%' identified by 'password';
Query OK, 0 rows affected (0.05 sec)
MySQL [(none)]> grant all privileges on *.* to root@'%';
Query OK, 0 rows affected (0.06 sec)
MySQL [(none)]> flush privileges;
Query OK, 0 rows affected (0.05 sec)
MySQL [(none)]> create user 'zabbix'@localhost identified by 'zabbix';
Query OK, 0 rows affected (0.06 sec)
MySQL [(none)]> create user 'zabbix'@'%' identified by 'zabbix';
Query OK, 0 rows affected (0.06 sec)
MySQL [(none)]> grant all privileges on *.* to 'zabbix'@localhost;
Query OK, 0 rows affected, 1 warning (0.05 sec)
MySQL [(none)]> grant all privileges on *.* to 'zabbix'@'%';
Query OK, 0 rows affected (0.05 sec)
推荐阅读
- Mysql主从模式搭建
- 可是国内的永乐大钟,却无法复制 永乐大钟
- DNA的复制是你想象不到的更精彩 dna复制特点
- 空白代码复制粘贴?空白昵称代码如何复制
- 附:解决办法 电脑复制后不能粘贴是什么原因
- 冒险岛怪盗幻影偷什么技能啊?拒绝复制的 怪盗幻影女郎
- 奥黛丽·赫本|奥黛丽赫本:一代女神,无法复制的经典
- 文玩|文玩圈中珍贵的复制品,不但不是仿品,还具有收藏价值
- 王志文|王志文带儿子拍亲子照,爷俩就像复制粘贴一样,这孩子有点像邓伦
- iphone如何导出通讯录,苹果通讯录复制到sim卡教程