快轉到主要內容

Change root password in MySQL 8

·136 字
Computer-Science MySQL
目錄
SQL-Basic - 本文屬於一個選集。
§ : 本文

Change the password of root in mysql version 8


mysqld_safe
#

You maybe need sudo in your case.

1# turn off mysqld
2/etc/init.d/mysql stop
3
4# use safe mode
5mysqld_safe --skip-grant-tables &

If it show the error message:

1mysqld_safe Logging to '/var/log/mysql/error.log'.
2mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

Try this before run the safe mode of mysqld:

1mkdir -p /var/run/mysqld
2chown mysql:mysql /var/run/mysqld

Change password
#

In this mode, you can login root without password.

1mysql -u root

In the old version(MySQL version lower than 8), you may use SET PASSWORD=PASSWORD('password'); to change password.

But in version 8, you need to change the method:

1USE mysql;
2ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
3FLUSH PRIVILEGES;
4exit;

Start the service

1killall mysqld
2/etc/init.d/mysqld start

Try it

1mysql -u root -p
2# type password
Alpaca
作者
Alpaca
No one can stop my feet.
SQL-Basic - 本文屬於一個選集。
§ : 本文

相關文章

《SQL Basics-03》UPDATE、ALTER、DROP
·907 字
Computer-Science SQL Database

一些基礎常見的 SQL 語法。

《SQL Basics-02》SELECT、LIKE
·962 字
Computer-Science SQL Database

一些基礎常見的 SQL 語法。

《SQL Basics-01》CREATE、INSERT
·1421 字
Computer-Science SQL Database

一些基礎常見的 SQL 語法。

資料庫概念 DB、DBMS、SQL 之間的關係
·966 字
Computer-Science SQL Database

資料庫早已被大量使用,如果還分不清楚 Database 與 DBMS 及 SQL 的關係,那還真是場災難呢!

Ubuntu 更換 /Home 到新硬碟
·1364 字
Computer-Science Ubuntu Disk

如果發現當初掛載好的空間不夠用了,那麼擴充硬碟上去,然後照著步驟一步步的將檔案們搬家吧。

How to use PPPoE to connect network on Ubuntu?
·353 字
Computer-Science Ubuntu PPPoE

在 Ubuntu 用 PPPoE 連線中華電信固定 IP。