CentOS6安装MySQL8.0.12

最近搭建了一个mysql的服务器,采用最新的mysql版本,安装过程中还是遇到了问题,现对其搭建过程进行记录。

一.环境

  CentOS6.8 64位 MySQL8.0.11 最小化安装

二.准备工作

1、源码安装过程

1.安装依赖
      yum -y install wget  cmake gcc gcc-c++ ncurses  ncurses-devel  libaio-devel  openssl openssl-devel
2.下载源码包(直接从官网下载即可)
      wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.11.tar.gz      (此版本带有boost)
3.创建mysql用户
      groupadd mysql
      useradd -r -g mysql -s /bin/false mysql
4.创建安装目录和数据目录
      mkdir -p /usr/local/mysql
      mkdir -p /data/mysql

编译并安装MySQL 8.0.11

 1.解压源码包
      tar -zxf mysql-boost-8.0.11.tar.gz -C /usr/local
 2.编译&安装
      cd /usr/local/mysql-8.0.11
      cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=/usr/local/mysql-8.0.11/boost 
      make  && make install

2、二进制文件安装

直接下载文件安装包直接解压到想要的安装路径下即可,解压完成的目录如下:

drwxrwxr-x.  2 mysql root   4096 Aug 15 01:51 bin
drwxrwxr-x.  2 mysql root   4096 Aug 15 01:51 docs
drwxrwxr-x.  3 mysql root   4096 Aug 15 01:51 include
drwxrwxr-x.  5 mysql root   4096 Aug 15 01:51 lib
-rw-r--r--.  1 mysql root 301518 Aug 15 01:51 LICENSE
drwxrwxr-x.  4 mysql root   4096 Aug 15 01:50 man
-rw-r--r--.  1 mysql root    687 Aug 15 01:51 README
drwxrwxr-x. 28 mysql root   4096 Aug 15 01:50 share
drwxrwxr-x.  2 mysql root   4096 Aug 15 01:51 support-files

三.配置文件

​ 1.配置my.cnf文件

      cat /etc/my.cnf
      [mysqld]
      server-id=1
      port=3306
      basedir=/usr/local/mysql
      datadir=/data/mysql
    ##请根据实际情况添加参数

  2.目录权限修改

      chown -R mysql:mysql /data/mysql
      chmod 755 /usr/local/mysql -R
      chmod 755 /data/mysql -R

  3.初始化

      bin/mysqld --initialize --user=mysql --datadir=/data/mysql/
      bin/mysql_ssl_rsa_setup

  4.启动mysql

   bin/mysqld_safe --user=mysql &

  5.修改账号密码

  bin/mysql  -uroot -p
      mysql> alter user 'root'@'localhost' identified by "123456";
        mysql> show databases;
        +--------------------+
        | Database          |
        +--------------------+
        | information_schema |
        | mysql              |
        | performance_schema |
        | sys                |
        +--------------------+
      4 rows in set (0.00 sec)
    ##添加远程特账号
    mysql> create user root@'%' identified by '123456';
    Query OK, 0 rows affected (0.08 sec)
    mysql> grant all privileges on *.* to root@'%';
    Query OK, 0 rows affected (0.04 sec)
    mysql> flush privileges;
    Query OK, 0 rows affected (0.01 sec)

  6.创建软链接(非必要)

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

    mysql -h 127.0.0.1 -P 3306 -uroot -p123456 -e "select version();"

    mysql: [Warning] Using a password on the command line interface can be insecure.

    +-----------+

    | version() |

    +-----------+

    | 8.0.11    |

    +-----------+

  7.添加到启动(非必要)

 cp support-files/mysql.server /etc/init.d/mysql.server
       10.yum install -y mariadb-server         //安装mariadb-server
       11. systemctl start mariadb.service        //启动mysql
       12.systemctl enable mariadb.service        //添加开机启动项
       13.mysql -u root -p              //进入mysql
8.添加linux服务启动
# 修改support-files中的两个路径
bsedir=/usr/local/mysql-8.0.12
datadir=/home/mysql/mysql/data

然后将该文件拷贝/etc/init.d/目录下,文件名为你想要启动的名称,如mysqld;
则可以通过service [name] [operate]来进行mysql的启动,停止,重启。

四.安装过程中遇到的问题

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
解决方式:找到文件mysql.sock,将其软链到目录/tmp/下

你可能感兴趣的:(数据库)