MySQL日常的配置总结

前提是你 提交于 2019-12-04 13:47:28

MySQL 忘记密码

1:停掉数据库

2: 找到my.cnf 增加 skip-grant-tables #是安全登录 可以不使用密码 进行登录,

3:启动数据库

4:mysql -uroot

5:use mysql

6:update user set password = password('new_password') where user='root'

6.1 (5.7+) update user set authentication_string = password('new_password') where user='root';

7 退出

8 停掉数据库

9 my.cnf 注掉 skip-grant-tables

10 启动数据库

11  if ERROR 1820 (HY000): You must SET PASSWORD before executing this statement 

12 set password = password('newPassword')

MySQL 的主从数据库

1:调整主数据库的访问权限,从数据库可以进行访问(更改 mysql 数据库 user表 中的host列%表示任何IP)

2:找到 my.cnf 添加

server-id=1   //给数据库服务的唯一标识,一般为大家设置服务器Ip的末尾号
log-bin=master-bin3 log-bin-index=master-bin.index
log-bin-index=master-bin.index

 

3:查看日志 show master status

+-------------------+----------+--------------+------------------+

| File                        | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+-------------------+----------+--------------+------------------+

| master-bin.000003 |      106 |              |                  |

+-------------------+----------+--------------+------------------+

/**

    记住 上面的 参数, 对后面来说很急很关键

*/

4: 这样主数据库的配置就好了,现在可以重启了

-------------------------------------------------------------------------------------------

配置从数据库(配多少个都一样)

1: 找到my.cnf

[mysqld]
server-id=2
relay-log-index=slave-relay-bin.index
relay-log=slave-relay-bin

 

2:进到从数据库中:

输入:

change master to master_host='192.168.0.104', //Master 服务器Ip
master_port=3306,
master_user='repl',
master_password='mysql', 
master_log_file='file',//show master status --> file
master_log_pos=position;//show master status --> position

3:重启从数据库

总结 : 

    上面的操作全是看的别人的, 我配置的时候,重启了很多次, 但是认为没有必要, 所以在配置完后才重启,

    希望这能帮到你 ^_^

 

 

 

 

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!