安装
打开服务器终端执行如下:
sudo apt update
sudo apt install mysql-server # 等待安装完成
systemctl status mysql # 查看服务是否启动
mysql_secure_installation # 加固mysql服务
创建业务数据库
mysql -u root -p # 管理员登录 可以不输密码
create database test character set utf8; # 创建test数据库
show databases # 显示所有库
创建用户
use mysql # 进入musql实例
create user test identified by 'Test123456.'; # 创建 test用户,密码是
grant all privileges on test.* to 'test'@'%'; # 将test数据库所有对象权限给test用户
flush privileges; # 刷新权限
远程连接
一般情况此时数据库还存在问题,服务仅仅监听127.0.0.1:3306,网络上其他主机无法连接,打开服务器终端
service mysql stop # 停止mysql服务
vim /etc/mysql/mysql.conf.d/mysqld.cnf # 打开默认配置文件
如下:找到倒数第二行 bind-address ,地址修改成 0.0.0.0,保存退出
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
[mysqld]
#
# * Basic Settings
#
user = mysql
# pid-file = /var/run/mysqld/mysqld.pid
# socket = /var/run/mysqld/mysqld.sock
# port = 3306
# datadir = /var/lib/mysql
# If MySQL is running as a replication slave, this should be
# changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir
# tmpdir = /tmp
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 0.0.0.0
mysqlx-bind-address = 0.0.0.0
service mysql start # 启动mysql服务