官网: http://www.mysql.com
下载下来的文件为:mysql-boost-5.7.17.tar.gz
[root@server1 software]# tar -zxf mysql-boost-5.7.17.tar.gz
[root@server1 software]# ls
[root@server1 software]# cd mysql-5.7.17/
[root@server1 mysql-5.7.17]# ls
[root@server1 mysql-5.7.17]# vim README
[root@server1 mysql-5.7.17]# vim INSTALL
帮助文档里给我们的是一个网址,打开看看
可以用cmake的方式,这里我们看到这里只列出了几个选项,更多选项又被链接到了另外一个网址,打开看看
这么多选项,我们根据需要进行选择,先看看从cmake –help
这就尴尬了,没有安装cmake,看看本机yum源里的cmake版本
cmake跨平台工具是用来预编译mysql源码的,用于设置mysql的编译参数。如:安装目录、数据存放目录、字符编码、排序规则等。所以安装yum源里带的即可
[root@server1 mysql-5.7.17]# yum install -y cmake.x86_64
cmake –help似乎没提供什么我们需要的选项,还是参照mysql的官方文档来吧
编译环境
官方文档说明:http://dev.mysql.com/doc/refman/5.7/en/source-installation.html
从官方文档知:需要以下依赖库
[root@server1 mysql-5.7.17]# yum install -y make.x86_64 gcc-c++.x86_64 bison.x86_64 ncurses.x86_64
依赖库安装好了,我们将boost移至/usr/local下,方便使用
[root@server1 mysql-5.7.17]# cp -r boost/boost_1_59_0/ /usr/local/
[root@server1 mysql-5.7.17]# ls /usr/local/boost_1_59_0/
boost
由于是源码安装,不同于玉米安装,不会自动帮我们创建用户,所以需要我们创建用户
[root@server1 mysql-5.7.17]# groupadd mysql #添加mysql用户组
[root@server1 mysql-5.7.17]# useradd -r -g mysql -s /bin/false mysql #添加mysql用户
参考mysql官方文档说明:http://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html#cmake-general-options
[root@server1 mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_BOOST=/usr/local/boost_1_59_0/ -DSYSCONFDIR=/etc -DEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all
[root@server1 mysql-5.7.17]# rm -rf CMakeCache.txt
[root@server1 mysql-5.7.17]# yun install -y ncurses-devel
继续执行cmake预编译
[root@server1 mysql-5.7.17]# make ##可加参数-j根据CPU核数指定编译时的线程数,可以加快编译速度。默认为1个线程编译,经测试四核CPU,2G的内存,单先程编译完需要20分钟左右。
[root@server1 mysql-5.7.17]# makeinstall
[root@server1 mysql-5.7.17]# cd /usr/local/mysql/
[root@server1 mysql]# ll -d
drwxr-xr-x 10 root root 4096 Sep 23 22:45 .
[root@server1 mysql]# chown -R mysql:mysql .
[root@server1 mysql]# ll -d
drwxr-xr-x 10 mysql mysql 4096 Sep 23 22:45 .
[root@server1 mysql]# ./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2017-09-24T03:01:29.063554Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-09-24T03:01:29.068209Z 0 [ERROR] COLLATION 'utf8mb4_general_ci' is not valid for CHARACTER SET 'latin1'
2017-09-24T03:01:29.068253Z 0 [ERROR] Aborting
提示字符集有错
[root@server1 mysql]# vim /etc/my.cnf ##编辑:增加两个编码变量
#改成如下,如果没有该文件,可拷贝一份,命令如下
##cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cn
[client]
default-character-set=gbk ##增加的编码变量
[mysqld]
character_set_server=gbk ##增加的编码变量
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
在初始化即可
如果使用–initialize参数初始化系统数据库之后,会在~/.mysql_secret文件中生成root用户的一个临时密码,同时也在初始化日志中打印出来了,如下图(fy<;iif!U95r):
[root@server1 init.d]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@server1 init.d]# chkconfig --add mysqld ## 添加到系统服务
[root@server1 init.d]# chkconfig mysqld on ## 开机启动
[root@server1 ~]# /etc/init.d/mysqld ##查看提供哪些用法
Usage: mysqld {start|stop|restart|reload|force-reload|status} [ MySQL server options ]
[root@server1 ~]# /etc/init.d/mysqld start ##测试开启服务
Starting MySQL. SUCCESS!
[root@server1 ~]# /etc/init.d/mysqld stop ##测试停止服务
Shutting down MySQL. SUCCESS!
[root@server1 ~]# /etc/init.d/mysqld start ##开启服务
[root@server1 ~]# ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql ##添加软链接将mysql加入系统环境变量,或者通过配置环境变量,export PATH=/usr/local/mysql/bin:$PATH 或者vim /etc/profile
[root@server1 ~]# mysql -uroot -pfy<;iif!U95r ##密码为刚才初始化时生成的
-bash: !U95r: event not found ##秘密包含特殊字符,不能这样写
[root@server1 ~]# mysql -uroot -p
Enter password: ##输入密码
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) ##报错
[root@server1 ~]# ln -s /var/lib/mysql/mysql.sock /tmp ##软链接
[root@server1 ~]# mysql -uroot -p ##再来
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.17
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> ##登陆成功
mysql> set password for root@localhost=password('mypasswd');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
mysql> exit
Bye
[root@server1 ~]# mysql -uroot -pmypasswd
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.17 Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
修改成功,可以进行数据库的操作了
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> CREATE database mydatabase
-> ;
Query OK, 1 row affected (0.00 sec)
mysql> SHOW databases
-> ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mydatabase |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql> use mydatabase
Database changed
mysql> show tables
-> ;
Empty set (0.00 sec)
mysql>