源码安装mysql

一.环境

  CentOS7.4   64位  最小化安装

 

二.准备工作

  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

  3.创建mysql用户

groupadd mysql
useradd -r -g mysql -s /bin/false mysql

  4.创建安装目录和数据目录

mkdir -p /usr/local/mysql
mkdir -p /data/mysql

  

三.安装MySQL8.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

  3.配置my.cnf文件

vi /etc/my.cnf

   [mysqld]
   server-id=1
   port=3306
   basedir=/usr/local/mysql
   datadir=/data/mysql
   skip-grant-tables#第一次启动使用免密登陆,之后可以注释掉

  4.目录权限修改

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

  5.初始化

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

  6.启动mysql

bin/mysqld_safe &

  7.修改账号密码

bin/mysql -uroot -p

  输入回车可以直接登录

mysql> alter user 'root'@'localhost' identified by "123456";

  修改密码时候可能会出现

  The MySQL server is running with the--skip-grant-tables option

  异常

  此时输入

mysql> flush privileges;

 

  出现 Query OK, 0 rows affected (0.01 sec)

  之后再输入修改密码的sql就可以了

  8.添加远程登陆账号

  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)

  9.创建软链接

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

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

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

 

posted @ 2018-07-10 10:57  KylinStayHere  阅读(428)  评论(0编辑  收藏  举报