怎么在Ubuntu18.04中安裝MySQL

本篇文章為大家展示了怎么在Ubuntu18.04中安裝MySQL,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡(jiǎn)單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名與空間、網(wǎng)站空間、營(yíng)銷軟件、網(wǎng)站建設(shè)、東平網(wǎng)站維護(hù)、網(wǎng)站推廣。

提示:以下操作均在root權(quán)限下進(jìn)行。

# 查看有沒有安裝MySQL:

dpkg -l | grep mysql

# 安裝MySQL:

apt install mysql-server

怎么在Ubuntu18.04中安裝MySQL

安裝完成之后可以使用如下命令來檢查是否安裝成功:

netstat -tap | grep mysql

通過上述命令檢查之后,如果看到有 mysql 的socket處于 LISTEN 狀態(tài)則表示安裝成功。

怎么在Ubuntu18.04中安裝MySQL

登錄mysql數(shù)據(jù)庫(kù)可以通過如下命令:

mysql -u root -p

-u 表示選擇登陸的用戶名, -p 表示登陸的用戶密碼,現(xiàn)在是mysql數(shù)據(jù)庫(kù)是沒有密碼的,Enter password:處直接回車,就能夠進(jìn)入mysql數(shù)據(jù)庫(kù)。

然后通過 show databases; 就可以查看當(dāng)前的所有數(shù)據(jù)庫(kù)。

怎么在Ubuntu18.04中安裝MySQL

接下來,為了確保數(shù)據(jù)庫(kù)的安全性和正常運(yùn)轉(zhuǎn),對(duì)數(shù)據(jù)庫(kù)進(jìn)行初始化操作。這個(gè)初始化操作涉及下面5個(gè)步驟。

(1)安裝驗(yàn)證密碼插件。

(2)設(shè)置root管理員在數(shù)據(jù)庫(kù)中的專有密碼。

(3)隨后刪除匿名賬戶,并使用root管理員從遠(yuǎn)程登錄數(shù)據(jù)庫(kù),以確保數(shù)據(jù)庫(kù)上運(yùn)行的業(yè)務(wù)的安全性。

(4)刪除默認(rèn)的測(cè)試數(shù)據(jù)庫(kù),取消測(cè)試數(shù)據(jù)庫(kù)的一系列訪問權(quán)限。

(5)刷新授權(quán)列表,讓初始化的設(shè)定立即生效。

對(duì)于上述數(shù)據(jù)庫(kù)初始化的操作步驟,在下面的輸出信息旁邊我做了簡(jiǎn)單注釋。

root@ubuntu-virtual-machine:~# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin? #要安裝驗(yàn)證密碼插件嗎?

Press y|Y for Yes, any other key for No: N # 這里我選擇N
Please set the password for root here.

New password: #輸入要為root管理員設(shè)置的數(shù)據(jù)庫(kù)密碼

Re-enter new password: #再次輸入密碼

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y #刪除匿名賬戶
Success.

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

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N #禁止root管理員從遠(yuǎn)程登錄,這里我沒有禁止

... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y #刪除test數(shù)據(jù)庫(kù)并取消對(duì)它的訪問權(quán)限
- Dropping test database...
Success.

- Removing privileges on test database...
Success.

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

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y #刷新授權(quán)表,讓初始化后的設(shè)定立即生效
Success.

All done!

怎么在Ubuntu18.04中安裝MySQL

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

systemctl status mysql

顯示如下結(jié)果說明mysql服務(wù)運(yùn)行是正常的:

怎么在Ubuntu18.04中安裝MySQL

再次用mysql -u root -p命令,Enter password:處輸入剛設(shè)置的密碼,回車,就能夠進(jìn)入mysql數(shù)據(jù)庫(kù)。

使用 use mysql; 命令打開mysql命名的數(shù)據(jù)庫(kù),顯示當(dāng)前數(shù)據(jù)庫(kù)的表:show tables; 查詢user表里的數(shù)據(jù):select * from user;(user表里是mysql數(shù)據(jù)庫(kù)的所有賬戶信息)

怎么在Ubuntu18.04中安裝MySQL

現(xiàn)在配置mysql允許遠(yuǎn)程訪問,首先編輯 /etc/mysql/mysql.conf.d/mysqld.cnf 配置文件:

vim /etc/mysql/mysql.conf.d/mysqld.cnf

注釋掉bind-address = 127.0.0.1

怎么在Ubuntu18.04中安裝MySQL

保存退出,然后進(jìn)入mysql數(shù)據(jù)庫(kù),執(zhí)行授權(quán)命令:

mysql -u root -p
mysql> grant all on *.* to root@'%' identified by '你的密碼' with grant option;
mysql> flush privileges; # 刷新權(quán)限
mysql> exit

然后執(zhí)行exit命令退出mysql服務(wù),再執(zhí)行如下命令重啟mysql:

systemctl restartmysql

現(xiàn)在Windows下可以使用Navicat圖形化工具遠(yuǎn)程連接Ubuntu下的MySQL數(shù)據(jù)庫(kù),輸入剛授權(quán)遠(yuǎn)程權(quán)限的密碼。

這里順便再分享下:Navicat for MySQL 10.1.7安裝包

鏈接: https://pan.baidu.com/s/12P1BcvQsRetBY0jGIvwILw&shfl=shareset 提取碼: 8bft

怎么在Ubuntu18.04中安裝MySQL

上述內(nèi)容就是怎么在Ubuntu18.04中安裝MySQL,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

網(wǎng)站欄目:怎么在Ubuntu18.04中安裝MySQL
文章出自:http://www.muchs.cn/article6/jdodog.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁(yè)設(shè)計(jì)公司定制開發(fā)、網(wǎng)站營(yíng)銷、全網(wǎng)營(yíng)銷推廣App開發(fā)、外貿(mào)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站