CentOS 6 安装 MySQL 8.0.x

CentOS 6 安装 MySQL 8.0.x

一、 先查询是否安装MySQL(大多数CentOS 6 自带 MySQL5.1)

1.查询

rpm -qa|grep mysql
mysql-libs-5.1.73-7.el6.i686

2.有则卸载

rpm -e --nodeps mysql-libs

–nodeps 是消除依赖的意思

二、去官网复制yum下载链接用wget下载到服务器
链接:

mysql下载地址:https://dev.mysql.com/downloads/repo/yum/

命令:

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

成功执行结果:

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执行结果:

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

安装wget

yum -y install wget

三、安装
第一步:

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

执行成功结果:

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%]

第二步:

yum install mysql-server

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

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.查询是否安装成功

mysqladmin -V
mysqladmin  Ver 8.0.13 for Linux on i686 (MySQL Community Server - GPL)

6.开启MySqL

service mysqld start
Initializing MySQL database:  
                                                   [  OK  ]
Starting mysqld:                                           [  OK  ]

查看MySQL启动状态:

service mysqld status
mysqld (pid  3852) is running...

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

cat /var/log/mysqld.log

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

 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.命令行登录和修改密码

 mysql -uroot -p

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

mysql -uroot -p
Enter password: 
Welcome to the MySQL monito

r.

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)

四、远程登录(Navicat)
注意:需关闭防火墙或者开放3306端口
如果不关闭防火墙或开放3306端口,会报如下错误
2003 can't connect to MySQL server on ip(10060)
暂时关闭

service iptables stop

设置成开启不自启

chkconfig iptables off

开启3306端口

/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT 

保存配置

/etc/rc.d/init.d/iptables save 

#重启服务

/etc/rc.d/init.d/iptables restart 

远程登录会报如下错误:
1130- Host xxx is not allowed to connect to this MariaDb server
首先查看用户表,发现登录主机是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;

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

2059 - authentication plugin 'caching_sha2_password'

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

use mysql; 

更改加密方式

ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;

更新用户密码

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';

刷新权限

FLUSH PRIVILEGES;

连接成功

qq群点击链接加入群聊 可以一起学习

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值