Linux Centos 7.4安装mysql5.6

mysql5.6安装手册

linux系统:Centos 7.4(使用lsb_release -a查看版本信息)
mysql版本:mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz

下载地址

  • 最新版:http://dev.mysql.com/downloads/mysql/
  • 旧版:https://dev.mysql.com/downloads/mysql/5.6.html - (5.5.62 / 5.6.46 / 5.7.28)

安装步骤

0. 卸载老版本mysql

find / -name mysql

rm -rf 上边查找到的路径,多个路径用空格隔开

1. 下载、解压

进入安装目录

cd /usr/local

下载

wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz

解压

tar -zxvf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz

2. 重命名、删除安装包

重命名

mv mysql-5.6.46-linux-glibc2.12-x86_64 mysql

删除安装包

rm -f mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz

3. 添加mysql用户组和mysql用户

检查是否存在mysql用户组

groups mysql

若有,则跳过


若无,则添加

groupadd mysql
useradd -r -g mysql mysql

4. 进入mysql目录更改权限

cd mysql
chown -R mysql:mysql ./

5. 执行安装脚本

./scripts/mysql_install_db --user=mysql

遇到报错一
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
Data::Dumper

解决方法:

yum -y install autoconf

遇到报错二
Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决方法:

yum -y install libaio-devel

安装完之后修改当前目录拥有者为root用户,修改data目录拥有者为mysql

chown -R root:root ./
chown -R mysql:mysql data

mysql配置

6. 启动mysql

启动mysql

./support-files/mysql.server start

遇到报错一
./support-files/mysql.server: line 244: my_print_defaults: command not found
./support-files/mysql.server: line 264: cd: /usr/local/mysql: No such file or directory
Starting MySQLCouldn't find MySQL server (/usr/local/mysql/[FAILED]ld_safe)

报错原因:support-files/mysql.server文件中的mysql的安装目录跟实际的安装目录不符,需要修改该文件。
解决方法:

vim support-files/mysql.server

进入文件,修改以下内容


继续启动
遇到报错二
Starting MySQL.191129 15:40:20 mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
The server quit without updating PID file (/var/lib/mysql/i[FAILED]w0bd0i0xw8wr8Z.pid).

解决方法:

mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb

终于启动成功。
查看serve运行状态

ps aux | grep mysql

7. 登录mysql

./bin/mysql -uroot -p

或者使用

cd /usr/local/bin
./mysql -uroot -p 

首次登录mysql输入回车即可登录

遇到报错一
./bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!

解决方法:
查看/etc/my.cnf,发现socket=/var/lib/mysql/mysql.sock
执行命令,将/tmp/目录下的mysql.sock指向的连接是/var/lib/mysql/mysql.sock

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

8. 修改mysql密码

mysql> use mysql;
mysql> update user set password = password('123456') where user = root;

查看用户信息

mysql> select host, user, password from user;

9. 添加开机启动

首先需要将support-files/mysql.server服务脚本复制到/etc/init.d/,并重命名为mysql

cp support-files/mysql.server /etc/init.d/mysql

通过chkconfig命令将mysqld服务加入到自启动服务项中

chkconfig --add mysql

查看是否添加成功

chkconfig --list mysql

如果看到mysql的服务,并且3,4,5都是on的话则成功,如果是off,则执行

chkconfig --level 345 mysql on

启动mysql:service mysql start
重启mysql:service mysql restart
关闭mysql:service mysql stop
查看serve运行状态:service mysql status

10. 把mysql客户端放到默认路径

注意:建议使用软链过去,不要直接包文件复制,便于系统安装多个版本的mysql

ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql

11. 配置my.conf

vim my.conf

添加以下内容

character-set-server=utf8
lower_case_table_names=1
max_allowed_packet=100M

配置好之后,重启mysql服务

service mysql restart

问题集合

  1. 远程连接mysql配置
mysql> grant all privileges on *.* to root@'%' identified by '123456';
mysql> flush privileges;
  1. ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'

修改my.cnf:vim /usr/local/mysql/my.cnf

[mysqld]
skip-grant-table

重启mysql,输入mysql

mysql> delete from user where user='';
mysql> flush privileges;

还原my.cnf的配置,重启

参考文档

  1. https://www.jianshu.com/p/f4a98a905011
  2. https://www.cnblogs.com/hanmk/p/8513088.html

你可能感兴趣的:(Linux Centos 7.4安装mysql5.6)