Ubuntu18安裝與配置mysql

1、安裝mysql

sudo apt update

sudo apt install mysql-server

2、安裝配置

sudo mysql_secure_installation

#1

VALIDATE PASSWORD PLUGIN can be used to test passwords...

Press y|Y for Yes, any other key for No: N (我的選項(xiàng))

#2

Please set the password for root here...

New password: (輸入密碼)

Re-enter new password: (重復(fù)輸入)

#3

By default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to havea user account created for them...

Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (我的選項(xiàng))

#4

Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess atthe root password from the network...

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y (我的選項(xiàng))

#5

By default, MySQL comes with a database named 'test' thatanyone can access...

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的選項(xiàng))

#6

Reloading the privilege tables will ensure that all changesmade so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的選項(xiàng))?

3、檢查mysql服務(wù)狀態(tài)

systemctl status mysql.service

如果出現(xiàn)下圖,說明是正常的:

如果不行,啟動(dòng)mysql服務(wù)試試:

sudo service mysql start

4、設(shè)置連接mysql不使用sudo

首先,登錄:

sudo mysql -uroot

接下來的都是在mysql里敲得。

查看當(dāng)前用戶:

select user,host from mysql.user;

刪除root賬號:

drop user root@localhost;

重新創(chuàng)建root:

create user root@localhost identified by 'mysql';

授權(quán):

grant all privileges on *.* to root@localhost with grant option;

刷新權(quán)限:

flush privileges;

退出mysql,重新連接:

mysql -uroot -pmysql;

不用加sudo了,搞定。

5、重置密碼的方法

SET PASSWORD FOR root@'localhost' = PASSWORD('newpassword');

6、在Ubuntu18.04系統(tǒng)下徹底刪除MySQL的方法

轉(zhuǎn)載:Ubuntu18安裝并配置mysql

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容