[root@slave1 mysql57]# cat /var/log/mysqld.log |grep password 2022-02-03T09:59:22.090885Z 1 [Note] A temporary password is generated for root@localhost: AJDtlg*kM1W1
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysqld] # # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid validate_password=OFF #新添加
登录mysql
mysql -uroot -p回车输入/var/log/mysqld.log中的密码
设置密码(需要关闭密码验证插件validate_password=OFF)
set password for root@localhost=password('123456');
查看mysql现有账号
use mysql;
mysql> select user,host from user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)
添加远程账号
mysql> grant all privileges on *.* to root@'%' identified by 'admin888';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
centos添加3306端口
[root@slave1 mysql57]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@slave1 mysql57]# firewall-cmd --reload
success