Ubuntu18.04下安裝Mysql

一下操作需要在root用戶權限下進行。

切換到root用戶:

sudo -i

安裝mysql:

apt install mysql-server

等待一些時間,待安裝完成以後,

使用mysql -u root -p

來登錄,剛剛開始是沒有密碼的,直接回車就ok。

接下來,我們需要來完成一些初始化操作:

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!

檢測mysql的服務狀態:

systemctl status mysql

再次使用mysql -u root -p來登錄,只不過現在需要輸入剛纔設置的密碼了。

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

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

註釋掉bind-address          = 127.0.0.1

保存退出,然後進入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 restart mysql

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章