mysql5.7安装

回复 收藏

1.下载二进制包(免编译)到/usr/local/src/

[root@Kry123 ~]# cd /usr/local/src/

[root@Kry123 src]# wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz如果报错“-bash: wget: command not found”是因为没有安装wget其他版本下载:https://downloads.mysql.com/archives/community/安装:

[root@Kry123 src]# yum -y install wget

查看wget[root@Kry123 src]# rpm -qf `which wget`wget-1.12-5.el6_6.1.x86_64

2.解压[root@Kry123 src]# tar -zxvf mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz -C /usr/local

3.重命名/usr/local/mysql[root@Kry123 src]#mv mysql-5.7.12-linux-glibc2.5-x86_64/ /usr/local/mysql

4.建立mysql用户[root@Kry123 src]# useradd mysql -s/sbin/nologin -M

5.创建数据库存放目录[root@Kry123 src]# mkdir -p /data/mysql

6.修改目录的所属主、所属群组[root@Kry123 src]# chown -R mysql.mysql /data/mysql

7.配置my.cnf[root@Kry123 src]# cd /usr/local/mysql/support-files

[root@Kry123 support-files]# cp my-default.cnf /etc/my.cnf

[root@Kry123 support-files]#vim /etc/my.cnf

修改:datadir =/data/mysql #数据库存放位置

port =3306 #数据库端口

socket =/tmp/mysql.sock #socket

添加:explicit_defaults_for_timestamp #

log-error=/var/log/mysqld.err.log #错误日志存放位置

pid-file=/data/mysql/mysqld.pid #PID存放位置

注视:#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES    

8.初始化数据库

[root@Kry123 src]# cd /usr/local/mysql/mysql_install_db在/bin下面,然后mysql_install_db已经被废弃了,请使用“mysqld --initialize”来初始化,还有缺少一个“libaio.so”

[root@Kry123 mysql]# ./bin/mysql_install_db --user=mysql --datadir=/data/mysql

2015-04-12 21:19:33 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize2015-04-12 21:19:33 [ERROR] Child process: /usr/local/mysql/bin/mysqldterminated prematurely with errno= 322015-04-12 21:19:33 [ERROR] Failed to execute /usr/local/mysql/bin/mysqld --bootstrap --datadir=/data/mysql --lc-messages-dir=/usr/share/mysql --lc-messages=en_US-- server log begin --/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory    

报错“/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory”

说明没安装libaio解决方法:[root@Kry123 mysql]# yum -y intsall libaio再次运行,又有错误。

[root@Kry123 mysql]# ./bin/mysqld --initialize --user=mysql --datadir=/data/mysql

2015-04-13T05:21:29.047423Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2015-04-13T05:21:29.047521echoZ 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.2015-04-13T05:21:29.047527Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.2015-04-13T05:21:29.050206Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.2015-04-13T05:21:29.050238Z 0 [ERROR] Aborting错误:“ [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).”

解决办法:在my.cnf 中添加一条“explicit_defaults_for_timestamp”    

错误:“[Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.”

解决办法:在my.cnf中注视掉“sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES ” #扩展了解sql模式:http://www.tocker.ca/2013/11/01/proposal-to-simplify-sql-modes.html    

错误:“[ERROR] --initialize specified but the data directory has files in it. Aborting.”

解决办法:删除“/data/mysql”重新创建,并修改所属主和属群组。    

再次运行,有输出错误,成功勒。

[root@Kry123 mysql]# ./bin/mysqld --initialize --user=mysql --datadir=/data/mysql

2015-04-13T05:42:06.855604Z 0 [Warning] InnoDB: New log files created, LSN=457902015-04-13T05:42:07.189251Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2015-04-13T05:42:07.419990Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: d26a76e3-e19f-11e4-86ef-000c29cbe215.2015-04-13T05:42:07.428523Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2015-04-13T05:42:07.431642Z 1 [Note] A temporary password is generated for root@localhost: %j5Llo_UxdG09.(为mysql初始密码)

启动mysql[root@Kry123 mysql]# ./support-files/mysql.server start

Starting MySQL... ERROR! The server quit without updating PID file (/data/mysql/mysqld.pid).

查看报错日志cat /var/log/mysqld.log2015-04-13T05:54:18.541881Z 0 [ERROR] Can't start server: Bind on TCP/IP port: Address already in use2015-04-13T05:54:18.541892Z 0 [ERROR] Do you already have another mysqld server running on port: 3306 ?

解决办法:原因:是因为有3306被占用。

[root@Kry123 mysql]# netstat -nlp |grep mysql

tcp 0 0 :::3306 :::* LISTEN 2013/mysqldunix 2 [ ACC ] STREAM LISTENING 17384 2013/mysqld /var/lib/mysql/mysql.sock

[root@Kry123 mysql]# killall mysqld

[root@Kry123 mysql]# netstat -nlp |grep mysql    

再次执行启动命名,成功勒。

[root@Kry123 mysql]# ./support-files/mysql.server startStarting MySQL. SUCCESS!

10.登录修改初始密码

[root@Kry123 mysql]# ./bin/mysqladmin -h127.0.0.1 -uroot password '123123' -p'%j5Llo_UxdG0'或者登录数据库在修改[root@Kry123 mysql]# ./bin/mysql -h127.0.0.1 -uroot -p'%j5Llo_UxdG0'mysql>set password = password('mypass');

注:修改用户密码>update mysql.user set authentication_string=password('123123.a') where user='root' ;

11.指定环境变量[root@Kry123 ~]# vim /etc/profile.d/mysql.sh 

#所有定义环境变量都在profile.d下面定义。

#!/bin/bash

export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib    

[root@Kry123 ~]# source /etc/profile.d/mysql.sh [root@Kry123 ~]# echo $PATH/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin:/usr/local/mysql/lib

12.设置服务[root@Kry123 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

[root@Kry123 ~]# chkconfig --add mysqld

[root@Kry123 ~]# chkconfig --level 35 mysqld on

修改配置文件(适用于忘记登录密码)

vi /etc/my.cnf在[mysqld]下面增加一行skip-grant-tables

重启 /etc/init.d/mysqld restart

/usr/local/mysql/bin/mysql -uroot

 update mysql.user set authentication_string=password('123123') where user='root';

退出来后,更改my.cnf,去掉刚加的 skip-grant-tables重启 /etc/init.d/mysqld restart

二、sock使用"mysql -uroot -p" 命令这样直接登录mysql,不加入"-h"参数那么默认为"-h localhost"参数登录mysql,这样登录mysql是无需使用TCP/IP协议的而使用的sock,来自于[client]中定义的sock。如果不定义默认位置为/tmp/mysql.sock。那么问题来了,只在[mysqld]中定义socket = /data/mysql.sock ,那么使用“mysql -uroot -p”或“mysql -uroot -p -h localhost”登录时就会去找/tmp/mysql.sock,是无法找到mysql.sock的。个人认为最好的解决办法就是在[mysqld]中socket=/tmp/mysql.sock.

2017-07-11 10:23 举报
已邀请:
0

OO笨小猪

赞同来自:

学习经验分享了!

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: