CentOS8 安装MySql 8.0教程

1. 官网下载

Mysql官方下载

 

2. 将下载好的文件上传至服务器

/usr/local/tools
tar -xvf mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.21-linux-glibc2.12-x86_64 mysql-8.0.21

3. 添加系统用户组和用户

groupadd mysql useradd -r -g mysql mysql

进入文件夹: cd mysql-8.0.21

此时当前目录为: /usr/local/tools/mysql-8.0.21

4. 新建数据目录个临时目录

mkdir data tmp chmod 777 ./data ./tmp

新建并修改配置文件:

cd support-files touch  my-default.cnf vim  my-default.cnf 

    将以下内容写入文件,其中lower_case_table_names=1 表示忽略大小写敏感

[mysqld]

basedir = /usr/local/tools/mysql-8.0.21

datadir = /usr/local/tools/mysql-8.0.21/data

port = 3306

socket = /usr/local/tools/mysql-8.0.21/tmp/mysql.sock

lower_case_table_names=1



[client]

default-character-set=utf8

socket= /usr/local/tools/mysql-8.0.21/tmp/mysql.sock



[mysql]

default-character-set=utf8

socket= /usr/local/tools/mysql-8.0.21/tmp/mysql.sock

5. 修改当前目录为mysql用户

chown -R mysql:mysql ./

初始化Mysql配置表: 切换至目录:/usr/local/tools/mysql-8.0.21

bin/mysqld --initialize --user=mysql --basedir=/usr/local/tools/mysql-8.0.21 --datadir=/usr/local/tools/mysql-8.0.21/data 

执行结束会生成数据库root用户密码:

2020-07-20T10:02:45.666654Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.21) initializing of server in progress as process 40212 

2020-07-20T10:02:47.687058Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: VRie4S*c%TNq

如果执行失败,需要删除data 和tmp文件下所有内容,检查配置后重新执行初始化

6. 设置开机启动服务

进入support-files目录

cp mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
chkconfig --list mysql (检查是否启动成功)

Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'.

mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off

以上说明成功

7. 手动启动服务

vim /etc/profile (配置环境变量)
export PATH=$PATH:/usr/local/tools/mysql-8.0.21/bin:/usr/local/tools/mysql-8.0.21/lib
service mysql start  (start,stop,restart命令)
source /etc/profile

8. 登录Mysql,重置密码

mysql -uroot -pVRie4S*c%TNq (密码是上面生成的密码,特殊符号可能报错,重新执行的初始化)
alter user 'root'@'localhost' identified by 'root';(重置为root)
flush privileges;

9. 放行远程链接

确保防火墙关闭,或者端口放行

mysql->use mysql; 
mysql->update user set host = '%' where user ='root'; 
mysql->flush privileges; 
mysql->select 'host' from user where user='root'; 

10. MySQL8.0登录提示caching_sha2_password问题解决方法

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> SELECT Host, User, plugin from user;
+-----------+------------------+-----------------------+
| Host      | User             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)
mysql>  ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT Host, User, plugin from user;
+-----------+------------------+-----------------------+
| Host      | User             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)

 

 

  • 2
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值