Mysql8.0+CentOS8.0安装
? 由于MySQL版本不兼容原因,你需要安装MySQL5.7,而不是安装MySQL8,但是Centos8默认是安装MySQL8的,因为Centos8的AppStream仓库只包含MySQL8的包
环境
系统版本
mysql版本:
linux版本: CentOS 8
操作
yum安装mysql服务
yum install mysql-server
检查是否已经设置为开机启动MySQL服务
[root@localhost ~]# systemctl list-unit-files | grep mysqld
mysqld.service disabled
mysqld@.service disabled
设置开机启动
[root@localhost ~]# systemctl enable mysqld.service
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
# double check
[root@localhost ~]# systemctl list-unit-files|grep mysqld
mysqld.service enabled
mysqld@.service disabled
查看是否启动MySQL服务
[root@localhost ~]# ps -ef | grep mysql
root 34198 3968 0 06:01 pts/1 00:00:00 grep --color=auto mysql
[root@localhost ~]#
修改root用户密码
[root@localhost ~]# mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
# 登录报错
[root@localhost mysql]# systemctl start mysqld.service
[root@localhost mysql]# ps -ef | grep 'mysql'
mysql 34528 1 5 06:11 ? 00:00:00 /usr/libexec/mysqld --basedir=/usr
root 34609 3968 0 06:11 pts/1 00:00:00 grep --color=auto mysql
# 再次登录, 直接回车,没有密码
[root@localhost ~]# mysql -uroot -p
Enter password:
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'root' ;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
mysql>
创建一个新用户
mysql> create user mysql identified with mysql_native_password by 'mysql';
Query OK, 0 rows affected (0.00 sec)
# 删除用户
delete from mysql.user where Host ='localhost' and User = 'username';
drop user username;
# 授权
mysql> grant all on *.* to 'mysql'@'%';
Query OK, 0 rows affected (0.01 sec)
# 刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
开通3306端口
[root@localhost man]# firewall-cmd --add-port=3306/tcp --permanent
success
[root@localhost man]# firewall-cmd --reload
success
测试连接
|