CentOS7 64位安装mysql8.0教程

总所周知,MySQL 被 Oracle 收购后,CentOS 的镜像仓库中提供的默认的数据库也变为了 MariaDB,如果想了解 MariaDB 和 CentOS 的区别,可以参考官网介绍,想用 MariaDB 的同学可以参考 MariaDB 安装指南

  • 检查系统是否装有mysql:
[root@wzb101 ~]# rpm -qa | grep mysql
[root@wzb101 ~]# 

这里返回空值,说明没有安装

这里执行安装命令是无效的,因为centos-7默认是Mariadb,所以执行以下命令只是更新Mariadb数据库

yum install mysql

删除可用

yum remove mysql
  • 下载mysql的repo源
wget http://repo.mysql.com/mysql-community-release-el7-1.noarch.rpm
  • 安装mysql-community-release-el7-1.noarch.rpm包
rpm -ivh mysql-community-release-el7-1.noarch.rpm
  • 安装mysql(下载巨慢, 总之我是等了一天来)
 yum install mysql-server

安装后再次查看mysql

[root@wzb103 software]# rpm -qa|grep mysql
mysql-community-client-8.0.19-1.el7.x86_64
mysql-community-release-el7-1.noarch
mysql-community-common-8.0.19-1.el7.x86_64
mysql-community-libs-compat-8.0.19-1.el7.x86_64
mysql-community-libs-8.0.19-1.el7.x86_64
mysql-community-server-8.0.19-1.el7.x86_64

启动mysql:

systemctl start mysqld

设置系统启动时自动启动:

systemctl enable mysqld

查看启动状态:

systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 四 2020-03-12 09:34:25 CST; 24min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 38081 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 38160 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─38160 /usr/sbin/mysqld

3月 12 09:34:10 wzb103 systemd[1]: Starting MySQL Server...
3月 12 09:34:25 wzb103 systemd[1]: Started MySQL Server.
  • mysql第一次启动密码实在日志里面:
cat /var/log/mysqld.log | grep -i 'temporary password'
[root@wzb102 ~]# cat /var/log/mysqld.log | grep -i 'temporary password'
2020-03-12T01:42:53.824502Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: p1#Lqpe(B0ga

上面的密码是p1#Lqpe(B0ga

[root@wzb103 ~]# cat /var/log/mysqld.log | grep -i 'temporary password'
2020-03-12T01:34:16.811117Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: lOS>j1g7o)lm
2020-03-14T03:14:17.786223Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: hE?M/sdIq00Z
[root@wzb103 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.19

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'Abc!@123';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by 'Abc!@123';
Query OK, 0 rows affected (0.04 sec)

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> CREATE USER 'root'@'%' IDENTIFIED BY 'Abc!@123';
Query OK, 0 rows affected (0.03 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.03 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host from user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| root             | %         |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
5 rows in set (0.00 sec)

mysql> exit;
Bye
[root@wzb103 ~]# systemctl restart mysqld
[root@wzb103 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 六 2020-03-14 11:18:38 CST; 3s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 3596 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 3620 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─3620 /usr/sbin/mysqld

3月 14 11:18:36 wzb103 systemd[1]: Starting MySQL Server...
3月 14 11:18:38 wzb103 systemd[1]: Started MySQL Server.

重启之后去连接:

  • 设置数据库编码为utf8:

打开配置文件:

vim /etc/my.cnf

在[mysqld],[client],[mysql]节点下添加编码设置:

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
##  重启mysqld服务
[root@wzb102 software]# systemctl restart mysqld;
[root@wzb102 software]# systemctl status mysqld;

Navicat连接mysql5.7, 出现下面的问题:

上面的意思是说Navicat版本mysql版本不匹配, 不大建议通过降低mysql密码等级来解决, 建议升级Navicat版本, 我这边的Navicat版本升级到15就可以解决上面的问题

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值