CentOS6安装MySQL5.7

1、下载mysql的rpm包集合

wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar
tar -xvf mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar

2、安装前先删除自带的mysql-libs,因为版本太低了

yum remove mysql-libs

3、安装依赖,解决libnuma.so

yum install libaio numactl

4、安装mysql

rpm -ivh mysql-community-common-5.7.12-1.el6.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.12-1.el6.x86_64.rpm
rpm -ivh mysql-community-client-5.7.12-1.el6.x86_64.rpm
rpm -ivh mysql-community-server-5.7.12-1.el6.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.12-1.el6.x86_64.rpm

5、启动mysql

service mysqld start
chkconfig mysqld on

【注意】
如果报下面的错误
2018-08-30T07:11:53.357975Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.12) starting as process 19197 ...
2018-08-30T07:11:53.360683Z 0 [Note] InnoDB: PUNCH HOLE support available
2018-08-30T07:11:53.360698Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-08-30T07:11:53.360702Z 0 [Note] InnoDB: Uses event mutexes
2018-08-30T07:11:53.360705Z 0 [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
2018-08-30T07:11:53.360710Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-08-30T07:11:53.360714Z 0 [Note] InnoDB: Using Linux native AIO
2018-08-30T07:11:53.360902Z 0 [Note] InnoDB: Number of pools: 1
2018-08-30T07:11:53.360988Z 0 [Note] InnoDB: Using CPU crc32 instructions
2018-08-30T07:11:53.367267Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2018-08-30T07:11:53.373383Z 0 [Note] InnoDB: Completed initialization of buffer pool
2018-08-30T07:11:53.374793Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man
page of setpriority().
2018-08-30T07:11:53.386081Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2018-08-30T07:11:53.402721Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2018-08-30T07:11:53.402738Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2018-08-30T07:11:53.402779Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2018-08-30T07:11:53.408147Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2018-08-30T07:11:53.410150Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2018-08-30T07:11:53.410169Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2018-08-30T07:11:53.411692Z 0 [Note] InnoDB: 5.7.12 started; log sequence number 2522067
2018-08-30T07:11:53.411722Z 0 [ERROR] [FATAL] InnoDB: pthread_create returned 11
2018-08-30 03:11:53 0x7fc5b5079720 InnoDB: Assertion failure in thread 140487122458400 in file ut0ut.cc line 920
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.

则可以执行

ulimit -s unlimited

来临时解决,或者关闭InnoDB

6、初始密码修改及登录

a、修改密码第一种方式:
rpm安装mysql后,会自动初始化一个密码,在日志中,使用命令可以查看:

cat /var/log/mysqld.log | more

2016-04-22T15:39:28.240976Z 1 [Note] A temporary password is generated for root@localhost: lVxXU4pWRl;o

直接使用命令匹配出来

cat /var/log/mysqld.log |grep 'temporary password'
mysql -uroot -p
>lVxXU4pWRl;o

回车,然后修改密码,密码必须包含大写字母小写字母数字和符号,不然会提示:ERROR 1819 (HY000): Your password does not satisfy the current policy

>ALTER USER 'root'@'localhost' IDENTIFIED BY 'Password1234!';

b、修改密码第二种方式(也适用于忘记密码)

vi /etc/my.cnf

新加入一行

skip-grant-tables

重启mysql后

mysql -uroot -p
>use mysql;

不用输入密码直接进入

>update user set Host = '%', authentication_string = password('Password1234'), password_expired = 'N', password_last_changed = now() where user = 'root';
>flush privileges;

退出,编辑/etc/my.cnf,去掉skip-grant-tables,重启mysql,完毕

【备注】如果直接insert用户到mysql.user表中提示报错,那么则编辑/etc/my.cnf加入如下语句

sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

保存重启mysql,如果不想反向解析ip地址到域名可以在my.cnf中添加

skip-name-resolve

CentOS7安装MySQL5.7

1、下载MySQL安装包

wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

2、安装mysql 安装源

yum -y localinstall mysql57-community-release-el7-11.noarch.rpm

3、在线安装MySQL

yum -y install mysql-community-server

4、启动MySQL服务

systemctl start mysqld

5、设置开机启动

systemctl enable mysqld
systemctl daemon-reload