mysql5.8安装步骤

安装前准备

1、检查wget是否安装

这里注意如果没有安装wget,要先安装wget,再进行镜像源的修改,否则如果没有镜像源cache,wget也安装不了。

2、更换镜像源

cp原来的镜像文件

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

参考:https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.3e221b11UhLE8Q

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

更新缓存

yum clean all

yum makecache

可能出现:Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error(不影响实际操作,可以执行下面命令消除)

执行:

sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

再重新更新缓存

3、检查mysql可能残留

查看系统中是否自带安装mysql :yum list installed | grep mysql

删除系统自带的mysql及其依赖: yum -y remove mysql-libs.x86_64

安装mysql

参考官网:https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html

想要安装5.8版本,需要以下操作(默认是没有5.8版本的rpm)

wget https://dev.mysql.com/get/mysql80-community-release-el7-4.noarch.rpm

yum install mysql80-community-release-el7-4.noarch.rpm

yum repolist all | grep mysql

[root@localhost bin]# cat /etc/yum.repos.d/mysql-community.repo
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-preview]
name=MySQL Tools Preview
baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-7.5-community]
name=MySQL Cluster 7.5 Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-7.5-community/el/7/$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-7.6-community]
name=MySQL Cluster 7.6 Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-7.6-community/el/7/$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-8.0-community]
name=MySQL Cluster 8.0 Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-8.0-community/el/7/$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

安装mysql:sudo yum install mysql-community-server -y

初始化mysql

查看mysql状态: systemctl stauts mysqld

启动mysql:service mysqld start

[root@localhost yum.repos.d]# service mysqld
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
    
[root@localhost yum.repos.d]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 五 2021-12-10 18:09:37 CST; 30s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 1820 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 1891 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─1891 /usr/sbin/mysqld

设置开机自启动:chkconfig mysqld on

mysql默认使用配置文件地址:

[root@localhost ~]# which mysqld
/usr/sbin/mysqld

[root@localhost ~]# /usr/sbin/mysqld --verbose --help |grep -A 1 'Default options'
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf

获取mysql初始密码:grep “password” /var/log/mysqld.log

[root@localhost yum.repos.d]# grep "password" /var/log/mysqld.log
2021-12-10T10:09:32.866249Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ;1rqt<AqfgX

mysql连接

[root@localhost yum.repos.d]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.27

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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>

设置密码:

这里注意5.8之后必须先设置密码,才能修改密码规则等级。这里设置

mysql> set global validate_password.policy=0;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

这里设置没有起作用:
set global validate_password.policy=0;
set global validate_password.length=1;---最短长度为4,设置1不生效的
密码只能改复杂一点:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123';

方式2:修改 validate_password.check_user_name值为false。
SHOW VARIABLES LIKE 'validate_password%';
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password.check_user_name    | OFF   |
| validate_password.dictionary_file    |       |
| validate_password.length             | 4     |
| validate_password.mixed_case_count   | 1     |
| validate_password.number_count       | 1     |
| validate_password.policy             | LOW   |
| validate_password.special_char_count | 1     |
+--------------------------------------+-------+
再修改简单密码:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.01 sec)


连接MYSQL

方式一:

mysql> select host from user where user = 'root';
+-----------+
| host      |
+-----------+
| localhost |
+-----------+

mysql> update user set host = '%' where user='root';
mysql> flush  privileges;

方式2:使用grant,但5.8之后这个命令不能使用,总是提示语法错误。后面再研究吧。。。

GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘root’ WITH GRANT OPTION;

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐