溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

怎么在Ubuntu18.04中安裝MySQL

發布時間:2021-03-03 17:20:40 來源:億速云 閱讀:204 作者:Leah 欄目:服務器

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

提示:以下操作均在root權限下進行。

# 查看有沒有安裝MySQL:

dpkg -l | grep mysql

# 安裝MySQL:

apt install mysql-server

怎么在Ubuntu18.04中安裝MySQL

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

netstat -tap | grep mysql

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

怎么在Ubuntu18.04中安裝MySQL

登錄mysql數據庫可以通過如下命令:

mysql -u root -p

-u 表示選擇登陸的用戶名, -p 表示登陸的用戶密碼,現在是mysql數據庫是沒有密碼的,Enter password:處直接回車,就能夠進入mysql數據庫。

然后通過 show databases; 就可以查看當前的所有數據庫。

怎么在Ubuntu18.04中安裝MySQL

接下來,為了確保數據庫的安全性和正常運轉,對數據庫進行初始化操作。這個初始化操作涉及下面5個步驟。

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

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

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

(4)刪除默認的測試數據庫,取消測試數據庫的一系列訪問權限。

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

對于上述數據庫初始化的操作步驟,在下面的輸出信息旁邊我做了簡單注釋。

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? #要安裝驗證密碼插件嗎?

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

New password: #輸入要為root管理員設置的數據庫密碼

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管理員從遠程登錄,這里我沒有禁止

... 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數據庫并取消對它的訪問權限
- 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 #刷新授權表,讓初始化后的設定立即生效
Success.

All done!

怎么在Ubuntu18.04中安裝MySQL

檢查mysql服務狀態:

systemctl status mysql

顯示如下結果說明mysql服務運行是正常的:

怎么在Ubuntu18.04中安裝MySQL

再次用mysql -u root -p命令,Enter password:處輸入剛設置的密碼,回車,就能夠進入mysql數據庫。

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

怎么在Ubuntu18.04中安裝MySQL

現在配置mysql允許遠程訪問,首先編輯 /etc/mysql/mysql.conf.d/mysqld.cnf 配置文件:

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

注釋掉bind-address = 127.0.0.1

怎么在Ubuntu18.04中安裝MySQL

保存退出,然后進入mysql數據庫,執行授權命令:

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

然后執行exit命令退出mysql服務,再執行如下命令重啟mysql:

systemctl restartmysql

現在Windows下可以使用Navicat圖形化工具遠程連接Ubuntu下的MySQL數據庫,輸入剛授權遠程權限的密碼。

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

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

怎么在Ubuntu18.04中安裝MySQL

上述內容就是怎么在Ubuntu18.04中安裝MySQL,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女