Ubuntu 安裝MySQL

1、下載mysql-apt-config資源包(資源包地址:https://dev.mysql.com/downloads/repo/apt/

2、將資源包放入apt庫

sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb

3、更新apt庫

sudo apt-get update

4、安裝mysql服務(此過程中存在配置密碼等,自行配置)

sudo apt-get install mysql-server

5、配置初始化信息

sudo mysql_secure_installation

root後輸入密碼

weison@ubuntu19-04:~$ sudo 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: 

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) : N(選擇N,不刪除匿名用戶)

 ... skipping.


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(選擇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) : N(選擇N,不刪除test數據庫)

 ... skipping.
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(選擇Y,修改權限立即生效)
Success.

All done! 

6、配置遠程訪問

# 登陸mysql
sudo mysql -uroot -p
#切換數據庫
use mysql;
#查詢用戶表命令:
select User,authentication_string,Host from user;

訪問權限說明:host默認都是localhost訪問權限

host值 訪問權限
localhost 本地連接
% 本地+遠程連接

7、創建一個用於遠程登陸的賬戶

create user 'ubuntu'@'%' identified by '你的密碼';
(ubuntu爲用戶名)

8、任何機器都能訪問

grant all privileges on *.* to 'ubuntu'@'%' with grant option;

9、授權用戶遠程訪問權限

GRANT ALL ON *.* TO 'ubuntu'@'%';

10、成功,鏈接地址爲你的服務器的ip

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