mysql8安装后初始化密码
環境:
Ubuntu19.10
Mysql版本:$ dpkg --list|grep mysql
ii ?mysql-client ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 8.0.18-0ubuntu0.19.10.1 ? ? ? ? ? ? ? ?all ? ? ? ? ?MySQL database client (metapackage depending on the latest version)
ii ?mysql-client-8.0 ? ? ? ? ? ? ? ? ? ? ? ? ? 8.0.18-0ubuntu0.19.10.1 ? ? ? ? ? ? ? ?amd64 ? ? ? ?MySQL database client binaries
ii ?mysql-client-core-8.0 ? ? ? ? ? ? ? ? ? ? ?8.0.18-0ubuntu0.19.10.1 ? ? ? ? ? ? ? ?amd64 ? ? ? ?MySQL database core client binaries
ii ?mysql-common ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 5.8+1.0.5ubuntu2 ? ? ? ? ? ? ? ? ? ? ? all ? ? ? ? ?MySQL database common files, e.g. /etc/mysql/my.cnf
ii ?mysql-server ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 8.0.18-0ubuntu0.19.10.1 ? ? ? ? ? ? ? ?all ? ? ? ? ?MySQL database server (metapackage depending on the latest version)
ii ?mysql-server-8.0 ? ? ? ? ? ? ? ? ? ? ? ? ? 8.0.18-0ubuntu0.19.10.1 ? ? ? ? ? ? ? ?amd64 ? ? ? ?MySQL database server binaries and system database setup
ii ?mysql-server-core-8.0 ? ? ? ? ? ? ? ? ? ? ?8.0.18-0ubuntu0.19.10.1 ? ? ? ? ? ? ? ?amd64 ? ? ? ?MySQL database server binaries
?
#---------1045 (28000)問題有以下兩種情況-------------------------------
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: YES)-----這次是這個問題
#############################下面的記錄是失敗的(只適用于mysql5.7)############################
?
1.
Root權限下面:
subl /etc/mysql/mysql.conf.d/mysqld.cnf
?
[mysqld]
下面加入
skip-grant-tables
2.
service mysql restart
3.
新開一個終端,輸入mysql即可進入mysql
#-----------------------------------------
舊版本的mysql(5.X),因為我一開始誤以為mysql5.x和mysql8.x是一致的:
??"mysql>update mysql.user set password=PASSWORD('新密碼') where User='root'; "
?
下面是修改plugin(大多數情況下不需要這一步,如果修改root權限后無效則需要這一步進行確認):
mysql> use mysql;
mysql> select plugin from user where user = 'root';
+-----------------------+
| plugin ? ? ? ? ? ? ? ?|
+-----------------------+
| mysql_native_password |
+-----------------------+
1 row in set (0.00 sec)
mysql> update user set plugin='mysql_native_password';
mysql> select plugin from user where user = "root";
?
然后
mysql> FLUSH PRIVILEGES;
?
查看修改過得密碼:
mysql> select User,Host, authentication_string from user
? ? -> ;
+------------------+-----------+------------------------------------------------------------------------+
| User ? ? ? ? ? ? | Host ? ? ?| authentication_string ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|
+------------------+-----------+------------------------------------------------------------------------+
| root ? ? ? ? ? ? | % ? ? ? ? | appleyuchi ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
確保上述表格中沒有空用戶,若有,則先按照[2]操作,然后回到本文
mysql>quit
#-----------------------------------------
subl /etc/mysql/mysql.conf.d/mysqld.cnf
刪除skip-grant-tables
在終端輸入下面的命令刷新:
service mysql restart
然后按照[1]鏈接操作
?
就可以一鍵登錄mysql了
###############下面是成功的完整記錄(適用于mysql8,來自[3], 但是與[3]略有不同)##########################
# gedit /etc/mysql/mysql.conf.d/mysqld.cnf?
[mysqld]下面加入skip-grant-tables保存.
service mysql restart
systemctl restart mysql
# mysql
mysql> use mysql;
?
mysql> select user,host from user;
+------------------+-----------+
| user ? ? ? ? ? ? | host ? ? ?|
+------------------+-----------+
| debian-sys-maint | localhost |
| mysql.infoschema | localhost |
| mysql.session ? ?| localhost |
| mysql.sys ? ? ? ?| localhost |
+------------------+-----------+
4 rows in set (0.00 sec)
mysql> flush privileges;
mysql> CREATE USER 'appleyuchi'@'%' IDENTIFIED with mysql_native_password ?BY 'appleyuchi';
mysql> SHOW VARIABLES LIKE 'validate_password%';?
mysql> ?flush privileges;?
mysql> GRANT ALL PRIVILEGES ON *.* TO 'appleyuchi'@'%' WITH GRANT OPTION;
mysql> flush privileges;
?
?
# gedit /etc/mysql/mysql.conf.d/mysqld.cnf?
[mysqld]下面用#注釋掉skip-grant-tables保存.
#service mysql restart
###################################################################################################
最終效果如下:
$ mysql -uappleyuchi -p
Enter password: (這里輸入的是appleyuchi)
Welcome to the MySQL monitor. ?Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.18-0ubuntu0.19.10.1 (Ubuntu)
Copyright (c) 2000, 2019, 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>?
?
?
Reference:
[1]https://blog.csdn.net/appleyuchi/article/details/79228240
[2]http://www.imooc.com/article/263671
[3]https://blog.csdn.net/zhouzhiwengang/article/details/87378046
?
?
總結
以上是生活随笔為你收集整理的mysql8安装后初始化密码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Missing space before
- 下一篇: pymysql.err.Internal