1.下载源码
-
wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.13.tar.gz
2.解压
-
tar zxvf mysql-5.7.13.tar.gz
3.安装必要的包
-
sudo yum install cmake gcc-c++ ncurses-devel perl-Data-Dumper libicu-devel libquadmath-devel python-devel bzip2-devel
4.安装Boost
-
wget http://jaist.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.zip
-
unzip boost_1_59_0.zip
-
cd boost_1_59_0
-
./bootstrap.sh
-
./b2
-
sudo ./b2 install
5.清除MariaDB
系统安装完成后,默认安装了mariadb-libs包,需要先清除掉,因依赖关系,系统会同时删除掉postfix。
-
sudo yum remove mariadb-libs
6.生成makefile
加上-DWITH_SYSTEMD=1可以使用systemd控制mysql服务,默认是不开启systemd的。
7.编译
8.安装
mysql将会安装到/usr/local/mysql路径。
9.添加mysql用户和组
-
sudo groupadd mysql
-
sudo useradd -r -g mysql mysql
10.修改目录和文件权限,安装默认数据库
-
cd /usr/local/mysql
-
sudo chown -R mysql .
-
sudo chgrp -R mysql .
-
sudo bin/mysqld --initialize-insecure --user=mysql
-
sudo bin/mysql_ssl_rsa_setup
-
sudo chown -R root .
-
sudo chown -R mysql data
至此,MySQL就可以启动运行了。
11.启动mysql
在/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
-
-
[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 = .....
-
# datadir = /data/mysql/data
-
# port = .....
-
server_id = 1
-
# 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
-
-
# max_connections = 10000
-
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
-
-
#error log
-
log_error = /usr/local/mysql/data/mysqld.err
-
-
#binary log
-
log-bin = mysql-bin
-
binlog_format = mixed
-
# expire_logs_day = 30
-
-
#slow query log
-
slow_query_log = 1
-
slow_query_log_file = /var/log/mysql/slow.log
-
long_query_time = 3
-
log-queries-not-using-indexes
-
log-slow-admin-statements
若系统无
文件,则新建该文件,并将读写权限开放给mysql用户。
mysql默认将mysqld.service文件安装到了mysql安装目录下的 usr/lib/systemd/system/,将mysqld.service复制到/usr/lib/systemd/system/目录下
-
cd /usr/local/mysql/
-
sudo cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
在mysqld.service,把默认的pid文件指定到了/var/run/mysqld/目录,而并没有事先建立该目录,因此要手动建立该目录并把权限赋给mysql用户。
-
cd /var/run
-
sudo mkdir mysqld
-
sudo chown -R mysql mysqld
-
sudo chgrp -R mysql mysqld
现在可以使用systemd启动mysql了
-
sudo systemctl start mysqld
12.修改root密码并开放网络登录
-
/usr/loca/mysql/bin/mysql -uroot
-
use mysql;
-
UPDATE user SET authentication_string = PASSWORD('test2015') WHERE user = 'root';
-
GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'rootpasswd';
-
FLUSH PRIVILEGES;
至此,安装基本完成了,一个mysql就能用了。
(责任编辑:IT) |