步骤一:安装mysql5.7
apt install mysql-server
安装完成后使用netstat -tap | grep mysql验证是否安装成功
步骤二:数据库初始化
mysql_secure_installation根据提示选择y或nSecuring 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?
#要安装验证密码插件吗? 选择N
Please set the password for root here.
#输入要为root管理员设置的数据库密码
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.
# 删除匿名账户 选择Y
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
# 禁止root管理员从远程登录 选择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.
# 删除test数据库并取消对它的访问权限 选择Y
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
# 刷新授权表,让初始化后的设定立即生效 选择Y
操作完成后使用systemctl status mysql检查mysql安装状态
步骤三:开启远程访问和修改数据库端口
vim /etc/mysql/mysql.conf.d/f
将bind-address的值从127.0.0.1改为0.0.0.0
将port的值从3306改为你想设置的值
步骤四:重启mysql
systemctl restart mysql