mysql 初始化无法设置password

今日长缨在手,何时缚住苍龙。这篇文章主要讲述mysql 初始化无法设置password相关的知识,希望能为你提供帮助。
填加skip-grant-tables
vim /etc/my.cnf
skip-grant-tables


启动systemctl start mysqld,mysql -uroot -p提示:

[root@ops1 ~]# mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Cant connect to local MySQL server through socket /var/lib/mysql/mysql.sock (2)



建立软链接
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
或者
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock


重启mysql并进入mysql
systemctl restart mysqld

[root@ops1 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.Commands end with ; or \\g.
Your MySQL connection id is 3
Server version: 5.6.51 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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>



【mysql 初始化无法设置password】配置root的password
mysql> update user set password=password(123456) where user="root";
ERROR 1046 (3D000): No database selected
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 password=password(123456) where user="root";
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4Changed: 4Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit


    推荐阅读