安装
mysql官网
https://dev.mysql.com/downloads/
找到yum repo.
执行
yum localinstall https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm
yum install mysql mysql-server
启动mysql服务
systemctl start mysqld
修改mysql root用户名密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
查看服务端口
mysql> show global variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0.07 sec)
mysql> select host,user,password from mysql.user;
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
上面这是mysql5.6及以下版本的查看命令, mysql5.7之后的数据库里mysql.user表里已经没有password这个字段了,password字段改成了authentication_string。
mysql> select host,user,authentication_string from mysql.user;
+-----------+------------------+------------------------------------------------------------------------+
| host | user | authentication_string |
+-----------+------------------+------------------------------------------------------------------------+
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+------------------+------------------------------------------------------------------------+
4 rows in set (0.01 sec)
更改roo用户名密码
MariaDB [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
创建用户
MariaDB [(none)]> CREATE USER 'kevin'@'%' IDENTIFIED BY '123456';
授权权限
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* to 'kevin'@'%' WITH GRANT OPTION;
设置root允许远程登录
MariaDB [(none)]> UPDATE mysql.user set host='%' WHERE user='root';