CentOS7MySQL数据库配置及远程访问
mysql 8.0.18官网源
https://dev.mysql.com/downloads/repo/yum/
找到适合的linux7版本,点击download,跳过打赏
右键点击复制下载地址
https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
终端输入
#> wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
安装
#> yum -y localinstall mysql80-community-release-el7-3.noarch.rpm
#> yum -y install mysql-community-server
开机启动
# systemctl start mysqld
# systemctl enable mysqld
# systemctl daemon-reload
获取临时密码
#> vim /var/log/mysqld.log
登录mysql使用mysql库
mysql> use mysql
允许远程主机,使用用户root登录
8.0.18要先新增用户
mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'YourPassword';
Query OK, 0 rows affected (0.04 sec)
再赋予权限
mysql> grant all privileges on *.* to 'root'@'%';
Query OK, 0 rows affected (0.03 sec)
另外,如果远程连接的时候报plugin caching_sha2_password could not be loaded这个错误,
可以尝试修改密码加密插件:
mysql> alter user 'root'@'%' identified with mysql_native_password by 'YourPassword';
赋权
#> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'YourPassword' WITH GRANT OPTION;
刷新权限表【没啥屁用】
flush privileges;
mysql> select host,user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
5 rows in set (0.01 sec)
测试连接,搞定!