如果已经有安装的,用命令删掉
#yum -y remove ...安装完毕后,在 /var/log/mysqld.log 文件中会自动生成一个随机的密码,需要先取得这个随机密码
#grep "password" /var/log/mysqld.log 2017-08-06T04:23:22.939636Z 1 [Note] A temporary password is generated for root@localhost: aZqHg=eQG9Nq使用临时密码登陆mysql并更新用户 root 的密码
#[root@iZjafzbmqur2lzZ ~]# mysql -u root -paZqHg=eQG9Nq mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.19 Copyright (c) 2000, 2017, 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>打印以上信息表示登陆成功,设置用户 root 可以在任意 IP 下被访问:
mysql> set password = password('新密码'); mysql> grant all privileges on *.* to root@"%" identified by "新密码"; //设置用户 root 可以在任意 IP 下被访问 mysql> grant all privileges on *.* to root@"localhost" identified by "新密码"; mysql> show databases; //查看当前都内置了哪些数据库 +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) mysql> exit //退出