概述
一、在线yum安装方式
1、下载安装yum Repository
下载地址
https://dev.mysql.com/downloads/repo/yum/
选择Red Hat Enterprise Linux 7下载
2、安装
切换到/usr/local目录,并上传
安装
rpm -ivh mysql80-community-release-el7-3.noarch.rpm
确认mysqlmysql安装版本
yum repolist | grep mysql
---------------------
mysql-connectors-community/x86_64 MySQL Connectors Community 141
mysql-tools-community/x86_64 MySQL Tools Community 105
mysql80-community/x86_64 MySQL 8.0 Community Server 161
安装mysql-community-server
yum install mysql-community-server
等待安装完成
二、安装文件安装
1、下载rpm文件
下载地址
https://dev.mysql.com/downloads/mysql/
操作系统选择
Red Hat Enterprise Linux / Oracle Linux
版本选择
Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit)
2、安装
上传至/usr/local目录下
rpm -ivh mysql-community-server-8.0.19-1.el7.x86_64.rpm
-----------------------------------------
warning: mysql-community-server-8.0.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
mysql-community-client(x86-64) >= 8.0.11 is needed by mysql-community-server-8.0.19-1.el7.x86_64
mysql-community-common(x86-64) = 8.0.19-1.el7 is needed by mysql-community-server-8.0.19-1.el7.x86_64
若安装失败,安装相应的依赖
首先安装mysql yum Repository资源
并安装相应依赖
yum install mysql-community-client.x86_64
yum install mysql-community-common.x86_64
三、配置mysql
1、启动mysql并查看状态
systemctl start mysqld.service
systemctl status mysqld.service
------------------------------
mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2020-03-21 16:01:22 CST; 48s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 32228 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 32358 (mysqld)
Status: "Server is operational"
CGroup: /system.slice/mysqld.service
└─32358 /usr/sbin/mysqld
Mar 21 16:00:50 instance-e7p2g0np systemd[1]: Starting MySQL Server...
Mar 21 16:01:22 instance-e7p2g0np systemd[1]: Started MySQL Server.
2、通过日志文件找出root密码
grep "password" /var/log/mysqld.log
-----------------------------------
2020-03-21T08:01:14.779932Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Xoe09ZF46.=Y
其中root@localhost:后面是密码
3、登录数据库修改密码
mysql -uroot -p
输入密码,登录成功后,此时不能做任何事情,必须修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
new password是修改的密码,若出现
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
密码设置达不到要求
注意:密码设置必须要有大小写字母加数字加特殊符号,不然不能配置成功
查看密码复杂度
SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 | 长度
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM | 复杂度
| validate_password.special_char_count | 1 |
+--------------------------------------+--------+
修改密码复杂度,和长度
set global validate_password.policy=LOW;
set global validate_password.length=4;
设置成功后,我们可以重新修改密码为123456
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
现在就不会报错
4、配置远程连接
切换到mysql数据库
use mysql
select host,user,authentication_string,plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host | user | authentication_string | plugin |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| localhost | root | $A$005$&pp53t 'otjkpZ.tUbc9ts9pj5gPelxbJeQb2.ySkmOAEE.pQdgz2V/ | caching_sha2_password |
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
我们看root是localhost只能支持本地访问,密码加密方式是caching_sha2_password
这种加密方式客服端连接时连接不上需要修改成 mysql_native_password方式
修改root的host为%
update user set host='%' where user='root';
给root授所有权限
grant all privileges on *.* to 'root'@'%' with grant option;
重新设置密码,并更改加密规则password为新密码
ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
更改密码加密方式为mysql_native_password
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
刷新权限
flush privileges;
重新连接成功
5、修改编码
mysql> status;
--------------
mysql Ver 8.0.19 for Linux on x86_64 (MySQL Community Server - GPL)
Connection id: 19
Current database: mysql
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 8.0.19 MySQL Community Server - GPL
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/lib/mysql/mysql.sock
Binary data as: Hexadecimal
Uptime: 1 hour 7 min 35 sec
Threads: 4 Questions: 801 Slow queries: 0 Opens: 494 Flush tables: 3 Open tables: 411 Queries per second avg: 0.197
--------------
修改配置文件/etc/my.conf
增加以下配置
character_set_server = utf8
collation-server=utf8_general_ci
重启
service mysqld restart
登录并查询
mysql> show variables like 'character%';
+--------------------------+--------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql-8.0/charsets/ |
+--------------------------+--------------------------------+
8 rows in set (0.01 sec)
最后
以上就是忐忑萝莉为你收集整理的CentOS 7安装Mysql8.0的全部内容,希望文章能够帮你解决CentOS 7安装Mysql8.0所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复