CentOS7下安装mysql-5.7.18

来源:互联网 发布:怎么看端口是否被占用 编辑:程序博客网 时间:2024/05/22 03:47

本文参考了:

http://blog.csdn.net/peng314899581/article/details/70241976

http://www.cnblogs.com/pythonal/p/6141516.html

1.      官网下载

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



2.将下载的mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar利用FileZila工具放进root中


3.进入:cd /usr/local

创建mysql文件夹:mkdir mysql

复制到mysql中

[root@xxxxx local]#cp /root/mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar./mysql

[root@xxxxx local]#cd mysql

解压tar文件

[root@xxxxx local]#tar –xvf mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar


4.安装

安装顺序rpm -ivh

mysql-community-common-5.7.18-1.el7.x86_64.rpm

mysql-community-libs-5.7.18-1.el7.x86_64.rpm(依赖于common)

mysql-community-client-5.7.18-1.el7.x86_64.rpm(依赖于libs)

mysql-community-server-5.7.18-1.el7.x86_64.rpm(依赖于common,client)

mysql-community-devel-5.7.18-1.el7.x86_64.rpm(MySQL头文件和库文件)

5.出错

执行第一个rpm -ivh mysql-community-common-5.7.18-1.el7.x86_64.rpm 出错


file /usr/share/mysql/czech/errmsg.sys frominstall of mysql-community-common-5.7.18-1.el7.x86_64 conflicts with file frompackage mariadb-libs-1:5.5.44-2.el7.centos.x86_64

这里说的很清楚和mariadb-libs-1:5.5.44-2.el7.centos.x86_64冲突了,执行yum -yremove mariadb-libs-1:5.5.44-2.el7.centos.x86_64,然后再安装,成功!

 

安装server又报错了


缺少perl,执行:yum install perl然后在安装,成功!

6.初始化数据库

[root@heting mysql]# mysqld --initialize--user=mysql

7.修改密码

Mysqld.log中的root@localhost: Sf.Gs=(wH6+r,密码是Sf.Gs=(wH6+r,一定要初始化数据库否则mysqld.log中什么都没有

[root@xxx mysql]# cat /var/log/mysqld.log

2017-05-12T07:59:48.175008Z 0 [Warning]TIMESTAMP with implicit DEFAULT value is deprecated. Please use--explicit_defaults_for_timestamp server option (see documentation for moredetails).

2017-05-12T07:59:53.343111Z 0 [Warning]InnoDB: New log files created, LSN=45790

2017-05-12T07:59:55.368266Z 0 [Warning]InnoDB: Creating foreign key constraint system tables.

2017-05-12T07:59:55.551715Z 0 [Warning] Noexisting UUID has been found, so we assume that this is the first time thatthis server has been started. Generating a new UUID:fc8d3c8d-36e8-11e7-8783-000c29d8df32.

2017-05-12T07:59:55.564802Z 0 [Warning]Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot beopened.

2017-05-12T07:59:55.575027Z 1 [Note] Atemporary password is generated for root@localhost:Sf.Gs=(wH6+r

[root@xxxx mysql]# systemctl startmysqld.service

[root@xxxx mysql]# mysql -uroot -p

Enter password:   (这里输入初始密码Sf.Gs=(wH6+r)

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.7.18

 

Copyright (c) 2000, 2017, Oracle and/or itsaffiliates. All rights reserved.

 

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarksof their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.

 

mysql> show databases;

ERROR 1820 (HY000): You must reset yourpassword using ALTER USER statement before executing this statement.

mysql> ALTER USER 'root'@'localhost'IDENTIFIED BY 'xxxxx';(这个的xxx是自己设置的新密码)

Query OK, 0 rows affected (0.00 sec)

8.可进入mysql修改密码,退出重新登入

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sys                |

+--------------------+

4 rows in set (0.00 sec)

 

mysql> use mysql

Database changed

mysql> show tables;

+---------------------------+

| Tables_in_mysql           |

+---------------------------+

| columns_priv              |

| db                        |

| engine_cost               |

| event                     |

| func                      |

| general_log               |

| gtid_executed             |

| help_category             |

| help_keyword              |

| help_relation             |

| help_topic                |

| innodb_index_stats        |

| innodb_table_stats        |

| ndb_binlog_index          |

| plugin                    |

| proc                      |

| procs_priv                |

| proxies_priv              |

| server_cost               |

| servers                   |

| slave_master_info         |

| slave_relay_log_info      |

| slave_worker_info         |

| slow_log                  |

| tables_priv               |

| time_zone                 |

| time_zone_leap_second     |

| time_zone_name            |

| time_zone_transition      |

| time_zone_transition_type |

| user                      |

+---------------------------+

31 rows in set (0.00 sec)

可以在修改密码

update user set password = password('1234')where user = 'root';

修改了密码要刷新

flush privileges;# 刷新

退出mysql,重新登陆:

mysql> exit

Bye

[root@xxxx mysql]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.7.18 MySQL CommunityServer (GPL)

 

Copyright (c) 2000, 2017, Oracle and/or itsaffiliates. All rights reserved.

 

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarksof their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.

9.在SQLyog里连接操作

(1)开启远程访问(用SQLyog可以访问操作)

[root@xxxx ]# grant all privileges on *.*to 'root' @'%' identified by 'xxx';(xxx自己的mysq密码)

[root@xxxx /]# flush privileges;(刷新)

(2)开启防火墙

先用的

[root@heting mysql]# /sbin/iptables -IINPUT -p tcp --dport 3306 -j ACCEPT

[root@heting mysql]# /etc/rc.d/iptablessave

-bash: /etc/rc.d/iptables: 没有那个文件或目录

发现没有,问题可能涉及没有安装iptables

安装iptables,参考http://www.cnblogs.com/kreo/p/4368811.html

然后再添加mysql

[root@xxx /]# iptables -A INPUT -p tcp--dport 3306 -j ACCEPT()

[root@xxx/]# service iptables save(保存操作)

/etc/sysconfig/iptables-config:行56:IPTABLES_MODULES-ip_nat_ftp: 未找到命令

iptables: Saving firewall rules to/etc/sysconfig/iptables:[  确定  ]

(3)在SQLyog里新建一个连接


MYSQL主机地址填linux的ip地址

先测试连接,再连接,通过上两步后就可以连接了

登陆mysql:

方式一:


方式二:



1 0