美文网首页
Linux Centos 7.4安装mysql5.6

Linux Centos 7.4安装mysql5.6

作者: 比德鲁滨逊 | 来源:发表于2019-11-29 17:00 被阅读0次

mysql5.6安装手册

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

下载地址

安装步骤

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

    mysql5.6安装手册 linux系统:Centos 7.4(使用lsb_release -a查看版本信息)my...

  • CentOS下安装jdk

    阿里云CentOS7.4(Linux)环境下安装java8-jdk1.8 环境 阿里云 CentOS 7.4 (L...

  • Linux | nginx-1.15.2

    本文系转载,原文: linux(CentOS7.4) 安装 Nginx 1.15.2 一、查看linux版本信息 ...

  • Centos7安装并配置mysql5.6

    Centos7安装并配置mysql5.6 下载安装mysql-5.6.39-linux-glibc2.5-x86_...

  • docker 部署spring boot 应用

    docker基础配置 linux(CentOS7.4)下安装dockeryum install 启动 Docker...

  • linux 安装mysql

    linux 安装mysql 基于CentOS7.4;mysql5.7 下载mysql源安装包wget http:/...

  • redis(一)环境搭建

    本文讲述如何安装redis,分Linux环境和Windows环境。Linux采用的演示系统是centos 7.4 ...

  • kubeadm v1.12.3安装

    使用kubeadm安装我们的kubernetes的测试环境 环境:CentOS Linux release 7.4...

  • CentOS下安装mysql

    环境 阿里云 CentOS 7.4 (Linux) 安装方法 本次安装使用rpm安装包的方式参考文章 https:...

  • 安装配置Syslog

    一、配置安装环境 linux centOS 7.4 配置网络,具体见https://www.jianshu.com...

网友评论

      本文标题:Linux Centos 7.4安装mysql5.6

      本文链接:https://www.haomeiwen.com/subject/tkpgwctx.html