URCloud

/ 0评 / 0/ 最后更新:2022-01-05
ubuntu安装mysql/mariadb,开启远程登录

步骤一:安装mysql

apt install mysql-server
#apt install mariadb-server

安装完成后验证是否安装成功

netstat -tap | grep mysql

步骤二:数据库初始化

mysql_secure_installation

根据提示选择y或n

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?
#要安装验证密码插件吗? 选择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管理员从远程登录 选择Y
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

操作完成后检查mysql安装状态

systemctl status mysql

步骤三:重启mysql/mariadb

systemctl restart mysql
#systemctl restart mariadb

关于远程登录:

在步骤二中我们关闭了允许root用户远程登录,推荐创建一个本地的拥有所有权限的管理员账号,再使用Navicat的ssh隧道功能实现远程登录。

创建用于远程登录的管理员账户

sudo mysql;
use mysql;
CREATE USER 'admin'@'localhost' IDENTIFIED BY 'strongpassword';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
0

Leave a Reply

Your email address will not be published.