1.安装mysql依赖
yum -y install gcc cmake make gcc-c++ ncurses-devel openssl-devel bison ncurses chkconfig lsof
2.安装boost
wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
tar -zxvf boost_1_59_0.tar.gz
3.下载mysql安装包
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.17.tar.gz
tar -zxvf mysql-5.7.17.tar.gz
cd mysql-5.7.17
4.增加mysql用户和用户组
groupadd mysql
useradd -g mysql mysql
5.创建数据目录
chown mysql.mysql -R /usr/local/mysql/
mkdir -p /var/mysql/
mkdir -p /var/mysql/data/
chown mysql.mysql -R /var/mysql/
6.编译安装
cmake \
-DMYSQL_DATADIR=/var/mysql/data \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DWITH_EXTRA_CHARSETS:STRING=all \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_engine=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/var/mysql/data \
-DMYSQL_TCP_PORT=3306 \
-DENABLE_DOWNLOADS=1 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost_1_59_0 \
-DMYSQL_USER=mysql
/*编译时间会比较漫长*/
make
make install
7.配置mysql文件
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[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.
basedir = /usr/local/mysql
datadir = /var/mysql/data
port = 3306
server_id = 1
socket = /var/mysql/mysql.socket
# 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
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
socket=/var/mysql/mysql.socket
8.增加mysql环境变量
vi /etc/profile
/*尾部增加*/
PATH=$PATH:/usr/local/mysql/bin
export PATH
/*保存成功后*/
source /etc/profile
9.初始化mysql数据
mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/var/mysql/data
10.启动mysql
/etc/init.d/mysqld start
没有报错的话 恭喜你安装成功了
11.进mysql修改密码
/*使用该命令 再敲mysql 可以直接进mysql*/
mysqld_safe --skip-grant-tables &
mysql
use mysql
update user set authentication_string=password('123abc') where user='root';
/*然后退出安全模式重新登录*/
mysql -uroot -p
123abc
/*这时候不管你怎么操作都会提示*/
You must reset your password using ALTER USER statement before executing this statement.
/*再设置一次密码*/
alter user 'root'@'localhost' identified by 'asdasd;657567';
12.增加远程mysql用户
Grant all on *.* to 'root'@'%' identified by 'Guang;123' with grant option;
flush privileges;