在centOS上安装完mysql, 登录MysqL时遇到错误
[root@MysqL-server Downloads]# MysqL -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
关键要用MysqLD_OPTS="--skip-grant-tables"重新启动MysqL服务
[root@MysqL-server Downloads]# systemctl stop MysqLd
[root@MysqL-server Downloads]# systemctl set-enviroment MysqLD_OPTS="--skip-grant-tables"
UnkNown operation 'set-enviroment'.
[root@MysqL-server Downloads]# systemctl set-environment MysqLD_OPTS="--skip-grant-tables"
[root@MysqL-server Downloads]# systemctl start MysqLd
[root@MysqL-server Downloads]# myslq -u root
bash: myslq: command not found...
Similar command is: 'MysqL'
[root@MysqL-server Downloads]# MysqL -u root
Welcome to the MysqL monitor. Commands end with ; or \g.
Your MysqL connection id is 3
Server version: 5.7.18 MysqL Community Server (GPL)
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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| MysqL |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.06 sec)
MysqL> use MysqL
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MysqL> update user set authentication_string=password('root') where user = 'root';
Query OK, 1 row affected, 1 warning (0.07 sec)
Rows matched: 1 Changed: 1 Warnings: 1
MysqL> flush previleges;
ERROR 1064 (42000): You have an error in your sql Syntax; check the manual that corresponds to your MysqL server version for the right Syntax to use near 'previleges' at line 1
MysqL> flush priviledges;
ERROR 1064 (42000): You have an error in your sql Syntax; check the manual that corresponds to your MysqL server version for the right Syntax to use near 'priviledges' at line 1
MysqL> flush privileges;
Query OK, 0 rows affected (0.11 sec)
MysqL> quit
Bye
[root@MysqL-server Downloads]# systemctl stop MysqLd
[root@MysqL-server Downloads]# systemctl unset-environment MysqLD_OPTS
[root@MysqL-server Downloads]# systemctl start MysqLd
[root@MysqL-server Downloads]# MysqL -u root -p
Enter password:
Welcome to the MysqL monitor. Commands end with ; or \g.
Your MysqL connection id is 3
Server version: 5.7.18
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>
参考:https://stackoverflow.com/questions/33510184/change-MysqL-root-password-on-centos7