linuxsir首页 LinuxSir.Org | Linux、BSD、Solaris、Unix | 开源传万世,因有我参与欢迎您!
网站首页 | 设为首页 | 加入收藏
您所在的位置:主页 > Linux数据库 >

CentOS 6 安装 MySQL 8.0.x

时间:2019-01-04  来源:未知  作者:admin666

1.先查询是否安装MySQL

大多数CentOS 6 自带 MySQL5.1

命令:

rpm -qa|grep mysql

执行:

[root@lifan ~]# rpm -qa|grep mysql
mysql-libs-5.1.73-7.el6.i686

2.若有则卸载

rpm -e --nodeps mysql-libs

--nodeps 是消除依赖的意思

3.去官网复制yum下载链接用wget下载到服务器

https://dev.mysql.com/downloads/repo/yum/


CentOS 6 安装 MySQL 8.0.x

命令:

wget https://dev.mysql.com/get/mysql80-community-release-el6-1.noarch.rpm

成功:

[root@lifan ~]# wget https://dev.mysql.com/get/mysql80-community-release-el6-1.noarch.rpm
--2018-12-10 06:40:42--  
...
Length: 25800 (25K) [application/x-RedHat-package-manager]
Saving to: “mysql80-community-release-el6-1.noarch.rpm”

2018-12-10 06:40:42 (95.8 MB/s) - “mysql80-community-release-el6-1.noarch.rpm” saved [25800/25800]

若没有wget

[root@lifan ~]# wget https://dev.mysql.com/get/mysql80-community-release-el6-1.noarch.rpm
-bash: wget: command not found

安装wget

yum -y install wget

4.安装

第一步:

rpm -ivh mysql80-community-release-el6-1.noarch.rpm

执行成功结果:

[root@lifan ~]# rpm -ivh mysql80-community-release-el6-1.noarch.rpm
warning: mysql80-community-release-el6-1.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
1:mysql80-community-relea########################################### [100%]
[root@lifan ~]# 

第二步:

yum install mysql-server

执行后会跳出2次选择,输入y回车继续即可,如:

[root@lifan ~]# yum install mysql-server
Loaded plugins: fastestmirror
...
Install       5 Package(s)
Total download size: 452 M
Installed size: 1.7 G
Is this ok [y/N]: y

输入y继续安装:

...
Total                                                                                                                              16 MB/s | 452 MB     00:28     
warning: rpmts_HdrFromFdno: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
Userid : MySQL Release Engineering <mysql-build@oss.Oracle.com>
Package: mysql80-community-release-el6-1.noarch (installed)
From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y

最后出现如下指令,安装成功:

Installed:
mysql-community-server.i686 0:8.0.13-1.el6                      
Dependency Installed:
mysql-community-client.i686 0:8.0.13-1.el6  mysql-community-common.i686 0:8.0.13-1.el6  mysql-community-libs.i686 0:8.0.13-1.el6  numactl.i686 0:2.0.9-2.el6 
Complete!

5.查询是否安装成功

[root@lifan ~]# mysqladmin -V
mysqladmin  Ver 8.0.13 for Linux on i686 (MySQL Community Server - GPL)

6.开启MySqL

[root@lifan ~]# service mysqld start
Initializing MySQL database:  
                                                   [  OK  ]
Starting mysqld:                                           [  OK  ]

查看MySQL启动状态:

[root@lifan ~]# service mysqld status
mysqld (pid  3852) is running...

7.查看系统给root自动生成的密码

cat /var/log/mysqld.log

执行结果(密码在第二行最后):

[root@lifan ~]# cat /var/log/mysqld.log
2018-12-10T12:19:20.303739Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.13) initializing of server in progress as process 3620
2018-12-10T12:19:24.878215Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: >J9tXQXwK3y=
2018-12-10T12:19:29.237165Z 0 [System] [MY-013170] [Server] /usr/sbin/mysqld (mysqld 8.0.13) initializing of server has completed
2018-12-10T12:19:32.011310Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.13) starting as process 3852
2018-12-10T12:19:33.144590Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2018-12-10T12:19:33.201007Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.13'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server - GPL.
2018-12-10T12:19:33.272837Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060

8.命令行登录和修改密码

[root@lifan ~]# mysql -uroot -p
Enter password: 

输入上一步骤查看的密码(输入时不显示任何字符):

[root@lifan ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor. 
...
mysql> 

修改密码:

mySql5.7之后,必须修改密码后才能操作.
并且对密码要求严格,至少8位,包含大小写等,若想设置成123456,则要以下两条命令:

mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password.length=1;
Query OK, 0 rows affected (0.00 sec)

设置密码:

mysql> alter user user() identified by '123456';
Query OK, 0 rows affected (0.09 sec)

9.远程登录(Navicat)

注意:需关闭防火墙或者开放3306端口

service iptables stop #暂时关闭
chkconfig iptables off #设置成开启不自启
==========
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT #开启3306端口 
/etc/rc.d/init.d/iptables save #保存配置
/etc/rc.d/init.d/iptables restart #重启服务 

远程登录会报如下错误:


首先查看用户表,发现登录主机是localhost,当然不能登录,把root用户的localhost设置为%,这样任意主机都可以连接。

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

mysql> update user set host = '%' where user ='华悦棋牌root';

再刷新一下:

flush privileges;

这时该问题已解决,若报如下错误,则是版本加密方式的改变

登录后请依次执行如下命令:

use mysql; 

ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER; #更改加密方式

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';#更新用户密码

FLUSH PRIVILEGES;#刷新权限

再次连接成功:

Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx

友情链接