1.MySQL的编译安装,需要使用cmake和Boost C++库,因此在进行安装前,需要提前安装好cmake及编译器。
[root@oel6 ~]# yum -y install gcc gcc-c++ ncurses ncurses-devel cmake
2.下载MySQL源代码,选择下载Generic Linux (Architecture Independent), Compressed TAR Archive Includes Boost Headers版本,该版本包含boost库信息,不需要单独下载[root@oel6 local]# wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.15.tar.gz3.添加mysql用户
[root@oel6 local]# groupadd mysql
[root@oel6 local]# useradd -r -g mysql -s /bin/nologin mysql
4.解压MySQL安装介质
[root@oel6 local]# tar -zxvf mysql-boost-5.7.15.tar.gz
[root@oel6 local]# cd mysql-5.7.15/
5.编译安装MySQL
[root@oel6 local]# mkdir -p /mysql/data
[root@oel6 local]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/mysql/data \
-DWITH_BOOST=/usr/local/mysql-5.7.15/boost/boost_1_59_0 \
[root@oel6 mysql-5.7.15]# make
[root@oel6 mysql-5.7.15]# make install
清除编译错误信息
[root@oel6 mysql-5.7.15]# make clean
[root@oel6 mysql-5.7.15]# rm CMakeCache.txt
6.初始化MySQL数据库
[root@oel6 ~]# cd /usr/local/mysql/
[root@oel6 mysql]# chown -R mysql:mysql ./
[root@oel6 mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/data
2016-10-06T05:11:36.422748Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-10-06T05:11:36.832157Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-10-06T05:11:36.900930Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-10-06T05:11:36.961751Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 5b4533be-8b83-11e6-927a-0800279bbbbf.
2016-10-06T05:11:36.963090Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-10-06T05:11:36.964712Z 1 [Note] A temporary password is generated for root@localhost: ;uIY2:ZVrv)u[root@oel6 mysql]# bin/mysql_ssl_rsa_setup --datadir=/mysql/data
Generating a 2048 bit RSA private key
......+++
.........................................................................................................+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
...........................+++
............................................................................................................................................................................................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
.................+++
...........................................................................................................................+++
writing new private key to 'client-key.pem'
-----
MySQL 5.7.6 之前版本,使用下面命令进行初始化
bin/mysql_install_db --user=mysql
7.启动MySQL数据库 (编译安装的MySQL,会默认创建/etc/my.cnf文件)
[root@oel6 ~]# cd /mysql
[root@oel6 mysql]# mkdir log
[root@oel6 mysql]# mkdir run
[root@oel6 ~]# chown -R mysql:mysql /mysql
[root@oel6 mysql]# cat /etc/my.cnf
[mysqld] //非默认参数会影响通过服务方式启停数据库datadir=/mysql/data
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe][root@oel6 mysql]# bin/mysqld_safe --user=mysql &
[1] 27572
[root@oel6 mysql]# 2016-10-06T05:21:00.684235Z mysqld_safe Logging to '/mysql/log/mysqld.log'.
2016-10-06T05:21:00.709272Z mysqld_safe Starting mysqld daemon with databases from /mysql/data
8.登陆MySQL数据库
[root@oel6 ~]# vi /root/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin //环境变量中增加mysql的路径[root@oel6 ~]# . /root/.bash_profile
[root@oel6 mysql]# mysql -u root -h localhost -p
Enter password: ;uIY2:ZVrv)uWelcome to the MySQL monitor. Commands end with ; or \g.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'oracle';9.配置MySQL服务自启动
[root@oel6 ~]# cd /usr/local/mysql
[root@oel6 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@oel6 mysql]# chkconfig --add mysqld
[root@oel6 mysql]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
10.关闭MySQL数据库
[root@oel6 bin]# mysqladmin -u root shutdown
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
[root@oel6 bin]# mysqladmin -u root -p shutdown
Enter password:
2016-10-06T05:50:46.469848Z mysqld_safe mysqld from pid file /mysql/run/mysqld.pid ended
[1]+ Done mysqld_safe --user=mysql
11.通过服务进行MySQL启停
[root@oel6 bin]# service mysqld start
Starting MySQL. [ OK ]
[root@oel6 bin]# service mysqld stop
Shutting down MySQL. [ OK ]
12.登陆非默认端口MySQL[root@oel6 bin]# mysql -u root -P8000 -h localhost -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
创新互联-专业网站定制、快速模板网站建设、高性价比柳南网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式柳南网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖柳南地区。费用合理售后完善,十年实体公司更值得信赖。
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网页名称:MySQL5.7.15编译安装-创新互联
标题网址:
http://cdkjz.cn/article/cosdeh.html