一.安装MySQL,装备的安装包:mysql-5.7.12.tar.gz boost_1_59_0.tar.gz
1.下载软件包
[root@localhost ~]#wget http://dev.mysql.com/Downloads/MySQL-5.7/mysql-5.7.12.tar.gz [root@localhost ~]#wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz/download
2.卸载原先的原先的MySQL和boost,并检查
[root@localhost ~]#yum -y remove mysql-* boost-* [root@localhost ~]#rpm -qa mysql [root@localhost ~]#rpm -qa boost
3.安装MySQL需要的依赖包
[root@localhost ~]#yum -y install gcc gcc-c++ ncurses ncurses-devel bison libgcrypt perl cmake glibc-static
4.解压boost到指定路径下,安装MySQL的时候要指定这个路径的
[root@localhost ~]#tar -xf boost_1_59_0.tar.gz -C /usr/local/boost/
5.创建MySQL的运行用户,并查看下
[root@localhost ~]#groupadd mysql [root@localhost ~]#useradd -r -g mysql mysql [root@localhost ~]#id mysql
6.解压MySQL,并进入到解压目录
[root@localhost ~]#tar -xf mysql-5.7.12.tar.gz -C /usr/src [root@localhost ~]#cd /usr/src/mysql-5.7.12
7.配置、编译、安装
[root@localhost mysql-5.7.12]#cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost -DSYSCONFDIR=/etc [root@localhost mysql-5.7.12]#make && make install
可以make -j 来指定编译时用到的核心数来提高编译速度,如:指定用4个核心来安装:make -j 4
8.优化调整MySQL
[root@localhost mysql-5.7.12]#chown -R mysql:mysql /usr/local/mysql #赋权 [root@localhost mysql-5.7.12]#cp /usr/src/mysql-5.7.12/support-files/my-default.cnf /etc/my.cnf #复制配置文件 [root@localhost mysql-5.7.12]#cp /usr/src/mysql-5.7.12/support-files/mysql.server /etc/init.d/ #复制启动脚本到系统服务目录下 [root@localhost mysql-5.7.12]#chmod +x /etc/init.d/mysql.server #添加可执行权限
编写服务控制脚本:
[root@localhost mysql-5.7.12]#cat <<END >>/usr/lib/systemd/system/mysqld.service [Unit] Description=mysqldapi After=network.target [Service] Type=forking PIDFile=/usr/local/mysql/logs/mysqld.pid ExecStart=/etc/init.d/mysql.server start ExecReload=/etc/init.d/mysql.server restart ExecStop=/etc/init.d/mysql.server stop PrivateTmp=False [Install] WantedBy=multi-user.target END [root@localhost mysql-5.7.12]#echo "export PATH=$PATH:/usr/local/mysql/bin/" >>/etc/profile && source /etc/profile #将MySQL的命令添加到环境变量 [root@localhost mysql-5.7.12]#mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data #初始化MySQL
修改MySQL配置文件:
[root@localhost mysql-5.7.12]#cat <<END >/etc/my.cnf [mysqld] basedir = /usr/local/mysql datadir = /usr/local/mysql/data port = 3306 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES character_set_server=utf8 init_connect='SET NAMES utf8' log-error=/usr/local/mysql/logs/mysqld.log pid-file=/usr/local/mysql/logs/mysqld.pid END [root@localhost mysql-5.7.12]#mkdir /usr/local/mysql/logs && chown mysql:mysql /usr/local/mysql/logs/ #创建MySQLlog文件并重新赋权 [root@localhost mysql-5.7.12]#systemctl start mysqld #启动服务 [root@localhost mysql-5.7.12]#systemctl enable mysqld #设置开机自启
9.登陆MySQL,并修改密码
[root@localhost mysql-5.7.12]#mysql #初始化之后默认没有密码,直接输入mysql就可以登陆了 [root@localhost mysql-5.7.12]#alter user 'root'@'localhost' identified by 'root'; #修改密码