centos7下二进制安装mysql5.6

本秂侑毒 提交于 2020-03-27 14:54:49

1、检查系统中是否已安装mysql或mariadb.

  rpm -qa|grep mysql 

  rpm -qa|grep mariadb

如果为空,则  说明没有安装

  

  

2、卸载已安装的mariadb数据库

  rpm -qa|grep mariadb|xargs rpm -e --nodeps

3、再次查看已安装的 mariadb 数据库,确认是否卸载完成。

  rpm -qa|grep mariadb

4、下载mysql5.6二进制安装包

  https://dev.mysql.com/downloads/mysql/mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz

  上传到Linux服务器 /usr/local/下

5、安装mysql5.6(在/usr/local/mysql56)

  1、创建mysql用户账号

    useradd -s /sbin/nologin -M mysql

  2、解压压缩包、并重命名

    cd /usr/local

    tar -xzvf mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz

    mv mysql-5.6.47-linux-glibc2.12-x86_64 mysql56

  3、复制配置文件、并修改配置文件

    cp /usr/local/mysql56/support-files/my-default.cnf /etc/my.cnf

    修改配置文件

    

[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.

skip-name-resolve
user = mysql
basedir = /usr/local/mysql56
datadir = /usr/local/mysql56/data
port = 3306
server_id = 1
socket = /usr/local/mysql56/mysql.sock
character-set-server = utf8

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M    

  4、初始化数据库

  修改mysql56的属组

[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql56

  初始化,初始化失败缺少依赖包,安装 libaio.* 的依赖包。

[root@localhost ~]# /usr/local/mysql56/scripts/mysql_install_db \
> --defaults-file=/etc/my.cnf \
> --user=mysql \
> --basedir=/usr/local/mysql56 \
> --datadir=/usr/local/mysql56/data
Installing MySQL system tables.../usr/local/mysql56/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
[root@localhost ~]# yum install libaio.* -y

6、配置并启动mysql

[root@localhost ~]# cp /usr/local/mysql56/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# chmod 755 /etc/init.d/mysqld
[root@localhost ~]# sed -i 's#/usr/local/mysql#/usr/local/mysql56#g' /usr/local/mysql56/bin/mysqld_safe /etc/init.d/mysqld

  (mysql二进制安装默认的路径为 /usr/local/mysql,启动脚本里 /usr/local/mysql 需要更换

  启动mysql

  service mysqld start

[root@localhost ~]# service mysqld start
Starting MySQL.Logging to '/usr/local/mysql56/data/localhost.localdomain.err'.
. SUCCESS!

  说明mysql5.6成功启动

7、添加自启动(开机启动)

  chkconfig --add mysqld

  chkconfig mysqld on

  chkconfig --list mysqld

8、配置环境变量

[root@localhost ~]# echo 'export PATH=/usr/local/mysql56/bin:$PATH' >> /etc/profile
[root@localhost ~]# source /etc/profile

9、修改mysql密码

[root@localhost ~]# mysqladmin -u root password '123456'
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!

  解决方法:

   vi /etc/my.cnf

socket = /usr/local/mysql56/mysql.sock
改为:
socket = /tmp/mysql.sock 
[root@localhost ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
10、设置远程登录[root@localhost ~]# mysqladmin -u root password '123456'
Warning: Using a password on the command line interface can be insecure.
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.47 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456";
Query OK, 0 rows affected (0.00 sec)

mysql> quit;
Bye
[root@localhost ~]#

 远程登录,还需关闭防火墙

  systemctl stop firewalld

 

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!