一、問(wèn)題描述
今天,筆者為了練習(xí)sql,在ubuntu16.04上安裝了mysql。筆者在網(wǎng)上搜索了在ubuntu16.04安裝mysql的步驟,并跟著步驟一步步操作,然而,讓筆者無(wú)法明白的是,網(wǎng)上說(shuō)在安裝mysql的過(guò)程會(huì)彈出輸入密碼的窗口,然而筆者在安裝的過(guò)程中沒(méi)有彈出任何窗口,而且也沒(méi)有報(bào)錯(cuò)。正當(dāng)筆者在登錄mysql時(shí),問(wèn)題就出現(xiàn)了,如圖:
如圖,筆者嘗試多種輸入方式,但都得到了一個(gè)同樣地令人憂傷的結(jié)果,ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
為了明白這個(gè)問(wèn)題,筆者又在網(wǎng)上廣泛搜索,從
筆者的配置文件/etc/mysql/my.cnf下沒(méi)有[mysqld]這一段啊
后來(lái),筆者又在網(wǎng)上折騰了許久,終于在/etc/mysql/mysql.conf.d/mysqld.cnf 這個(gè)文件里找到了[mysqld]這一段,感動(dòng)啊
到此,筆者遇到問(wèn)題總算解決了,真是開(kāi)心呀!
下面筆者介紹自己的mysql安裝過(guò)程和問(wèn)題的具體解決過(guò)程。
二、mysql安裝過(guò)程
在ubuntu終端下依次輸入命令:
$ sudo apt update
$ sudo apt-get install mysql-server mysql-client
三、問(wèn)題解決過(guò)程
1.打開(kāi)/etc/mysql/mysql.conf.d/mysqld.cnf 文件,命令如下
$ sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
2.找到[mysqld]段,并加入一行“skip-grant-tables”,如下圖,
3.重啟mysql服務(wù),用空密碼進(jìn)入mysql管理命令行,切換到mysql庫(kù),操作命令如下,
$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
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 mysql.user set authentication_string=password('newpass') where user='root' and Host ='localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> update user set plugin="mysql_native_password";
Query OK, 0 rows affected (0.00 sec)
Rows matched: 3 Changed: 0 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> quit;
Bye
4.回到sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf,把剛才加入的那一行“skip-grant-tables”注釋或刪除掉。
5.再次重啟mysql服務(wù)sudo service mysql restart,使用新的密碼登陸,修改成功。
$mysql-u root -p new_pass
Welcome to the MySQL monitor. Commands end with ; or \g.
mysql>
6.至此,問(wèn)題解決
聯(lián)系客服