本文将演示如何在Ubuntu服务器上部署mysql,创建角色和赋予权限.
这是我参与「第三届青训营 -后端场」笔记创作活动的第4篇笔记
安装mysql
使用命令行安装mysql
sudo apt-get install mysql-server
配置mysql
初始化
命令行
sudo mysql_secure_installation
配置项如下:
-
VALIDATE PASSWORD COMPONENT 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 component? //是否开启强密码,避免出现过弱密码,这里选择Y
Press y|Y for Yes, any other key for No: y
-
There are three levels of password validation policy: LOW Length >= 8; MEDIUM Length >= 8, numeric, mixed case, and special characters; STRONG Length >= 8, numeric, mixed case, special characters and dictionary file. //选择密码强度,这里选择1
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
Please set the password for root here.
New password: //输入密码
Re-enter new password: //再次输入密码
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y //确认或再次输入其他密码
-
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
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 //是否移除初始数据库
- 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!
配置用户
用root进入mysql
sudo mysql -uroot -p
创建用户
create user MyUser@'localhost' identified by 'MyPassword';
授权(授予所有数据库的所有权限)
grant all privileges on *.* to MyUser@'localhost';