vm12下Centos6安装mysql5.7

一、下载mysql的rpm tar文件

文件名称:mysql-5.7.18-1.el6.x86_64.rpm-bundle.tar
官方地址:https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-1.el6.x86_64.rpm-bundle.tar

二、安装mysql

1、解压

# 将mysql-5.7.18-1.el6.x86_64.rpm-bundle.tar压缩包解压到/usr/wangzf/mysqlrpm/下
[[email protected] downloads]# tar -xvf mysql-5.7.18-1.el6.x86_64.rpm-bundle.tar -C ../mysqlrpm/
mysql-community-libs-compat-5.7.18-1.el6.x86_64.rpm
mysql-community-test-5.7.18-1.el6.x86_64.rpm
mysql-community-libs-5.7.18-1.el6.x86_64.rpm
mysql-community-common-5.7.18-1.el6.x86_64.rpm
mysql-community-embedded-5.7.18-1.el6.x86_64.rpm
mysql-community-embedded-devel-5.7.18-1.el6.x86_64.rpm
mysql-community-client-5.7.18-1.el6.x86_64.rpm
mysql-community-devel-5.7.18-1.el6.x86_64.rpm
mysql-community-server-5.7.18-1.el6.x86_64.rpm

# 查看解压后的rpm软件包
[[email protected] downloads]# cd ../mysqlrpm/
[[email protected] mysqlrpm]# ll
total 459488
-rw-r--r--. 1 7155 31415  23618836 Mar 20 05:40 mysql-community-client-5.7.18-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415    335496 Mar 20 05:40 mysql-community-common-5.7.18-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415   3747352 Mar 20 05:40 mysql-community-devel-5.7.18-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415  39086508 Mar 20 05:40 mysql-community-embedded-5.7.18-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 135869292 Mar 20 05:40 mysql-community-embedded-devel-5.7.18-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415   2177064 Mar 20 05:40 mysql-community-libs-5.7.18-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415   1723180 Mar 20 05:40 mysql-community-libs-compat-5.7.18-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 159060212 Mar 20 05:41 mysql-community-server-5.7.18-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 104881084 Mar 20 05:41 mysql-community-test-5.7.18-1.el6.x86_64.rpm

2、安装mysql

# 想要安装mysqlclient和mysqlserver,需要先安装common和libs
[[email protected] mysqlrpm]# rpm -ivh mysql-community-common-5.7.18-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:mysql-community-common ########################################### [100%]
[[email protected] mysqlrpm]# rpm -ivh mysql-community-libs-5.7.18-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:mysql-community-libs   ########################################### [100%]
[[email protected] mysqlrpm]# rpm -ivh mysql-community-client-5.7.18-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:mysql-community-client ########################################### [100%]
[[email protected] mysqlrpm]# rpm -ivh mysql-community-server-5.7.18-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:mysql-community-server ########################################### [100%]

# 查看已安装的与mysql相关的软件
[[email protected] mysqlrpm]# rpm -qa|grep -i  mysql
mysql-community-common-5.7.18-1.el6.x86_64
mysql-community-client-5.7.18-1.el6.x86_64
mysql-community-libs-5.7.18-1.el6.x86_64
mysql-community-server-5.7.18-1.el6.x86_64

3、启动mysql

# 查看mysql服务的状态
[[email protected] mysqlrpm]# service mysqld status
mysqld is stopped

# mysql尚未启动,使用service mysqld start启动(这里是第一次启动,会初始化一些参数)
[[email protected] mysqlrpm]# service mysqld start
Initializing MySQL database:                               [  OK  ]
Installing validate password plugin:                       [  OK  ]
Starting mysqld:                                           [  OK  ]

# 停止mysql服务
[[email protected] mysqlrpm]# service mysqld stop
Stopping mysqld:                                           [  OK  ]

# 启动mysql服务
[[email protected] mysqlrpm]# service mysqld start
Starting mysqld:                                           [  OK  ]

# 重启mysql服务
[[email protected] mysqlrpm]# service mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

三、修改root密码

# 关闭mysql服务
[[email protected] ~]# service mysqld stop
Stopping mysqld:                                           [  OK  ]

# 安全模式下启动mysql,并且跳过权限表的验证
[[email protected]192 ~]# mysqld_safe --skip-grant-tables &
[1] 1678
[[email protected]192 ~]# 2017-05-06T23:30:01.604144Z mysqld_safe Logging to ‘/var/log/mysqld.log‘.
2017-05-06T23:30:01.674987Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

# 准备登陆
mysql -u root -p

# 这里随便输入密码,都可以进入mysql
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.18 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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.

# 更改密码(这里设置的密码是1234)
mysql> update mysql.user set authentication_string=password(‘1234‘) where user=‘root‘ and Host = ‘localhost‘;
Query OK, 1 row affected, 1 warning (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 1

# 刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

# 退出mysql
mysql> quit
Bye

# 重启mysql
[[email protected] ~]# service mysqld restart
2017-05-06T23:17:47.067045Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
[2]-  Done                    mysqld_safe --skip-grant-tables

# 以root身份登陆
[[email protected] ~]# mysql -uroot -p

# 输入刚才设置的密码1234,正常使用mysql
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.18

Copyright (c) 2000, 2017, 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> 

四、远程访问mysql

1、centos开启防火墙端口3306

# 开放3306端口
[[email protected]192 ~]# /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

# 保存
[[email protected]192 ~]# /etc/rc.d/init.d/iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]

# 查看防火墙的状态
[[email protected]192 ~]# /etc/init.d/iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:3306
2    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:3306
3    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:8080
4    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
5    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0
6    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
7    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22
8    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination         

# 删除刚刚添加的端口
# 这里我原先已经开放了3306端口,再次添加又增加了一个3306,所以显示2个3306,这里我将num为2的那个3306删除
[[email protected]192 ~]# iptables -D INPUT 2

# 查看防火墙的状态(奇怪的是我原本也开放的有80端口,莫名其妙没了...)
[[email protected]192 ~]# iptables -L -n --line-number
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:3306
2    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:8080
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
4    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0
5    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
6    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22
7    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination         

2、修改mysql表,允许远程访问

# 登陆
[[email protected]192 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.18

Copyright (c) 2000, 2017, 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> GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘1234‘ WITH GRANT OPTION;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

# 在设置远程登录原先是提示错误。百度一番,需要设置root密码,好吧,我原先是1234,现在还设置为1234
mysql> SET PASSWORD = PASSWORD(‘1234‘);
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

# 发现是密码太脆弱,究其根本是由于mysql有密码验证的策略,那么这里设置一下
# 设置密码强度检查等级为0,0/LOW、1/MEDIUM、2/STRONG。
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

# 设置密码长度:8-->4
mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
|                          8 |
+----------------------------+
1 row in set (0.00 sec)

mysql> set global validate_password_length=4;
Query OK, 0 rows affected (0.00 sec)

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
|                          4 |
+----------------------------+
1 row in set (0.00 sec)

# 设置密码为1234
mysql> SET PASSWORD = PASSWORD(‘1234‘);
Query OK, 0 rows affected, 1 warning (0.00 sec)

# 设置允许远程访问
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘1234‘ WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

# 刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
# 退出
mysql> exit;
Bye

3、windows下远程连接vm12下centos6.9的mysql

Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

C:\Users\Administrator>mysql -h 192.168.22.130 -u root -p
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.7.18 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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>

最后就问下:惊不惊喜?意不意外?

时间: 2024-11-16 11:05:16

vm12下Centos6安装mysql5.7的相关文章

CentOS6.5_64bit下编译安装MySQL-5.6.23

转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/44785511 ************************************************************         CentOS6.5_64bit下编译安装MySQL-5.6.23 **************************************************************一.关闭防火墙chkconfig iptable

centos6.7下 编译安装MySQL5.7

centos6.7下编译安装MySQL5.7 准备工作 #-----依赖包及MySQL和boost安装包----- #yum包安装: shell> yum -y install gcc-c++ ncurses-devel cmake make perl gcc autoconf automake zlib libxml libgcrypt libtool bison #获取boost类库(5.7编译需要boost类库,编译时指定boost路径): shell> wget http://down

centos 下编译安装mysql5.1与mysql5.5

mysql5.1.60编译安装 1.tar -zxvf mysql* 2../configure 之前要make clean ./configure --prefix=/home/shk/mysql-5.1.60 \ --enable-local-infile \ --with-unix-socket-path=/home/shk/mysql-5.1.60/var/mysql.sock \ --with-tcp-port=5506 \ --enable-thread-safe-client \

centos下yum安装mysql5.6后,无法启动 MySQL Daemon failed to start

如果是全新安装应该就不会出现这个问题,升级安装的话,要运行 mysql_upgrade ,但是启动MYSQL就报错MySQL Daemon failed to start 如此就没办法运行mysql_upgrade升级MYSQL表了 因为是全新安装的数据库服务器就不管老数据了,直接把老的MYSQL数据库文件夹删除了,然后 运行 mysql_install_db 单独执行下命令,初始化mysql,test等数据库 初始化所有数据库以后,依然是无法启动,检查了MYSQL的日志发现没有权限,因为是RO

centos6.4下编译安装MySQL-5.5.33

若想在6.4版本下的centos编译安装MySQL必须使用新的编译器cmake. 1)安装cmake 直接yum安装 2)编译安装参数 使用cmake编译安装mysql-5.5.33,选项的方式有所改变: ./configure                cmake .            编译   ./configure –help         cmake . -LH or ccmake .   获取帮助 指定安装文件的安装路径时常用的选项:    -DCMAKE_INSTALL_P

centos6.5下yum安装mysql5.5

第一步就是看linu是否安装了mysql,经过rpm -qa|grep mysql查看到centos下安装了mysql5.1,那就开始卸载咯 2 接下来就是卸载mysql5.1了,命令:rpm -e mysql-libs --nodeps   yum中之后mysql5.1,安装还是5.1,现在就要去增加一个新的repo rpm -Uvh http://mirror.steadfast.net/epel/6/i386/epel-release-6-8.noarch.rpm   一共需要增加两个re

CentOS6.9 下编译安装MySQL5.7.19

官网:https://www.mysql.com/ 下载地址:https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.19.tar.gz 一.准备工作 1.下载mysql并解压 [[email protected] ~]# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.19.tar.gz [[email protected] ~]# tar xf mysql-5.7.19.ta

CentOS6.5下RPM安装Mysql5.6

一.升级操作 1.卸载旧版本 查看MySQL旧版本 rpm -qa|grep mysql rpm -qa|grep mariadb 卸载MySQL rpm -e --nodeps mysql-5.1.73-7.el6.x86_64 rpm -e --nodeps mysql-connector-odbc-5.1.5r1144-7.el6.x86_64 rpm -e --nodeps mysql-libs-5.1.73-7.el6.x86_64 rpm -qa|grep mysql 删除数据目录

centos6.6下编译安装mysql5.6之后启动失败:Starting MySQL... ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).

今天在编译安装mysql5.6时候出现Starting MySQL... ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).,当时就心碎了,之前安装时候好好的,在网上搜索帮助方法,可是没有和我一样的,有的说我没有给mysqld赋权限,可是我赋予他权限了,试了一堆方法,最后心灰意冷,准备删除mysql重新安装,就在我执行:yum remove mysql mysql