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