Ubuntu18.04 安装Mysql

1. 更新资源
#命令1
sudo apt-get update
#命令2
sudo apt-get install mysql-server
2. 初始化配置

sudo mysql_secure_installation

1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  2@  21  22  23  24  25  26  27  28  29  3@  #1  VALIDATE PASSWORD  Press ylY for Yes,  #2  PLUGIN can  any other  be used  key for  to  No:  Please set the password for root here...  New password:  Re-enter new password:  #3  By default, a MySQL installation has an  test passwords...  anonymous user  allowing anyone to log into MySQL without having to have  a user account created for them...  Remove anonymous users? (Press ylY for Yes, any other key for No)  Normally, root should only be al lowed to connect from  • localhost' . This ensures that someone cannot guess at  the root password from the network...  : N (fifii%-lfi)  Disallow root login remotely? (Press y I Y for Yes, any other key for No)  #5  By default, MySQL comes with a database named •test' that  anyone can access...  Remove test database and access to it? (Press y IY for Yes,  any other key for No)  #6  Reloading the privilege tables will ensure that  made so far will take effect immedi ate 1 y.  Reload privi lege tables now? (Press y IY for Yes,  a II changes  any other key for No)  : Y (fifii%-lfi)

3. 检查mysql服务状态

systemctl status mysql.service

新建用户/数据库

CREATE USER 'admin'@'%' IDENTIFIED BY '654312';

GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' IDENTIFIED BY '654312' with grant option;

FLUSH PRIVILEGES;

CREATE DATABASE IF NOT EXISTS hmi DEFAULT CHARSET utf8 COLLATE utf8_bin;

 CREATE DATABASE IF NOT EXISTS htc1100 DEFAULT CHARSET utf8 COLLATE utf8_bin;

CREATE DATABASE IF NOT EXISTS htc1100_alarm_log DEFAULT CHARSET utf8 COLLATE utf8_bin;

exit
4. 配置远程连接

# 注意:不同 mysql 版本此配置文件位置和名字可能不同

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf # mysql 5.7.23

#找到将bind-address = 127.0.0.1注销
#bind-address      = 127.0.0.1
bind-address      = 0.0.0.0
5. 修改后,重启MySQL服务器

sudo /etc/init.d/mysql restart

6. 检查MySQL服务器占用端口

netstat -nlt|grep 3306

posted @ 2021-05-10 19:42  MarkYUN  阅读(118)  评论(0)    收藏  举报