Linux下mysql-5.7.20安装

1 参考文档

https://dev.mysql.com/doc/refman/5.7/en/source-installation.html

https://dev.mysql.com/doc/refman/5.7/en/installing-source-distribution.html

https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html

2 安装

2.1 打开防火墙3306端口

$ sudo /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
$ sudo service iptables save

2.2 创建mysql用户

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

2.2 下载mysql和boost库(对应版本高于或低于这个版本都有问题) https://dev.mysql.com/doc/refman/5.7/en/source-installation.html

$ wget http://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
$ wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.20.tar.gz

安装

$ tar zxvf  boost_1_59_0.tar.gz
$ mv boost_1_59_0 /usr/local/boost

$ tar zxvf mysql-5.7.20.tar.gz && cd mysql-5.7.20/ && mkdir bld && cd bld/
$ cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DDOWNLOAD_BOOST=OFF -DWITH_BOOST=/usr/local/boost -DMYSQL_TCP_PORT=3306 ..

$ make && make install

$ mkdir /opt/mysql && mkdir /opt/mysql/data && mkdir /opt/mysql/log && touch /opt/mysql/log/mariadb.log

$ chown -R mysql:mysql /opt/mysql

配置文件调整

$ vi /etc/my.cnf

[mysqld]
datadir=/opt/mysql/data
socket=/tmp/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
# 忽略大小写配置
lower_case_table_names=1
log-bin=mysql-bin
binlog-format=ROW
server-id=1

[mysqld_safe]
log-error=/opt/mysql/log/mariadb.log
pid-file=/tmp/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

初始化mysql 系统数据表

$ /usr/local/mysql/bin/mysqld --initialize --user=mysql

*************************************************************************************

[Note] A temporary password is generated for root@localhost: a5goRy5Yez/t

获取临时密码:a5goRy5Yez/t

*************************************************************************************

启动

$ /usr/local/mysql/bin/mysqld_safe --user=mysql &

开启SSL

$ /usr/local/mysql/bin/mysql_ssl_rsa_setup

登录 MySQL

$ /usr/local/mysql/bin/mysql -u root -p

# 修改root初始密码
mysql> ALTER USER 'root'@'localhost' identified by 'sloth@linux';

# 允许root外部访问
mysql> use mysql
mysql> GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'sloth@linux';

配置自启动

$ cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql.server
$ chmod 755 /etc/init.d/mysql.server
$ chkconfig --add mysql.server
$ chkconfig --list

猜你喜欢

转载自www.cnblogs.com/jediz90/p/9221322.html