1、准备
cmake-3.6.0.tar.gz
bison-3.0.4.tar.gz
mysql-5.7.13.tar.gz (http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.13.tar.gz)
2、安装cmake 和 bison
首先可以查看下是否安装了 cmake
# rpm -qa |grep cmake
# tar zxvf cmake-3.6.0.tar.gz # cd cmake-3.6.0 # ./bootstrap # make && make install
# tar zxvf bison-3.0.4.tar.gz # cd bison-3.0.4 # ./configure # make && make install
3、安装Mysql
[root@localhost src]# mkdir -p /usr/local/mysql #Mysql安装目录
[root@localhost src]# mkdir -p /data/mysqldb #Mysql数据库数据文件目录
[root@localhost src]# tar -zxvf mysql-5.7.13.tar.gz
[root@localhost src]# cd mysql-5.7.13 [root@localhost mysql-5.7.13]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=gbk -DDEFAULT_COLLATION=gbk_chinese_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/mysqldb -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1 ... CMake Error at cmake/boost.cmake:81 (MESSAGE): You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory> This CMake script will look for boost in <directory>. If it is not there, it will download and unpack it (in that directory) for you. If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://example.com:80 Call Stack (most recent call first): cmake/boost.cmake:238 (COULD_NOT_FIND_BOOST) CMakeLists.txt:451 (INCLUDE) -- Configuring incomplete, errors occurred!
-DCMAKE_INSTALL_PREFIX=dir_name | 设置mysql安装目录 |
-DMYSQL_UNIX_ADDR=file_name | 设置监听套接字路径,这必须是一个绝对路径名。默认为/tmp/mysql.sock |
-DDEFAULT_CHARSET=charset_name | 设置服务器的字符集。 缺省情况下,MySQL使用latin1的(CP1252西欧)字符集。cmake/character_sets.cmake文件包含允许的字符集名称列表。 |
-DDEFAULT_COLLATION=collation_name | 设置服务器的排序规则。 |
-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 |
存储引擎选项: MyISAM,MERGE,MEMORY,和CSV引擎是默认编译到服务器中,并不需要明确地安装。 静态编译一个存储引擎到服务器,使用-DWITH_engine_STORAGE_ENGINE= 1 可用的存储引擎值有:ARCHIVE, BLACKHOLE, EXAMPLE, FEDERATED, INNOBASE (InnoDB), PARTITION (partitioning support), 和PERFSCHEMA (Performance Schema) |
-DMYSQL_DATADIR=dir_name | 设置mysql数据库文件目录 |
-DMYSQL_TCP_PORT=port_num | 设置mysql服务器监听端口,默认为3306 |
-DENABLE_DOWNLOADS=bool | 是否要下载可选的文件。例如,启用此选项(设置为1),cmake将下载谷歌所使用的测试套件运行单元测试。 |
注:重新运行配置,需要删除CMakeCache.txt文件
<<==========================================================================
解决:
(1)在预编译时添加相应的选项:cmake -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
(2)或者下载一个boost包,放到/usr/local/boost目录下,然后在cmake后面加选项-DWITH_BOOST=/usr/local/boost
==========================================================================>>
[root@localhost mysql-5.7.13]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=gbk -DDEFAULT_COLLATION=gbk_chinese_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/mysqldb -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:107 (FIND_CURSES)
cmake/readline.cmake:181 (MYSQL_USE_BUNDLED_EDITLINE)
CMakeLists.txt:479 (MYSQL_CHECK_EDITLINE)
-- Configuring incomplete, errors occurred!
See also "/usr/local/src/mysql-5.7.13/CMakeFiles/CMakeOutput.log".
<<=========================================================================
解决:
(1)安装ncurses-devel
yum -y install ncurses-devel
(2)删除CMakeCache.txt
rm CMakeCache.txt
(3)重新cmake
[root@localhost mysql-5.7.13]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=mysql.mysql -DDEFAULT_CHARSET=gbk -DDEFAULT_COLLATION=gbk_chinese_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/mysqldb -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
==========================================================================>>
[root@localhost mysql-5.7.13]# make
[root@localhost mysql-5.7.13]# make install
修改Mysql目录所有者和组
[root@localhost]# cd /usr/local/mysql
[root@localhost mysql]# chown -r mysql:mysql .
[root@localhost mysql]# cd /data/mysqldb
[root@localhost mysqldb]# chown -r mysql:mysql .
初始化Mysql数据库
[root@localhost mysql]# bin/mysql_install_db --user=mysql --datadir=/data/mysqldb
复制Mysql服务器启动配置文件
[root@localhost mysql]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
[root@localhost mysql]# vim /etc/my.cnf #修改配置文件
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
socket = /usr/local/mysql/mysql.sock
复制Mysql服务器启动脚本
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
配置PATH路径
[root@localhost mysql]# vim /etc/profile PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH export PATH [root@localhost mysql]# source /etc/profile
启动服务
[root@localhost mysql]# service mysqld start
登录Mysql
[root@localhost ~]# mysql -u root -p
修改Mysql用户密码
[root@localhost bin]# ./mysqladmin -u root -p password
Enter password:
New password:
Confirm new password:
Mysql5.7 mysql.user表 中没有password字段,用authentication_string 代替。
可能遇到的问题:
1、navicat连接报错
mysql> update user set host = '%' where user='root'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0
重启Mysql服务!
2、安装pdo_mysql扩展
[root@localhost lib]# cd /usr/local/mysql/lib/ [root@localhost lib]# ll total 349256 -rw-r--r--. 1 mysql mysql 14069930 Jul 18 19:54 libmysqlclient.a lrwxrwxrwx. 1 mysql mysql 20 Jul 18 20:14 libmysqlclient.so -> libmysqlclient.so.20 lrwxrwxrwx. 1 mysql mysql 24 Jul 18 20:14 libmysqlclient.so.20 -> libmysqlclient.so.20.3.0 -rwxr-xr-x. 1 mysql mysql 8120880 Jul 18 20:13 libmysqlclient.so.20.3.0 -rw-r--r--. 1 mysql mysql 335396804 Jul 18 20:08 libmysqld.a -rw-r--r--. 1 mysql mysql 29162 Jul 18 19:28 libmysqlservices.a drwxr-xr-x. 2 mysql mysql 4096 Jul 18 20:15 pkgconfig drwxr-xr-x. 3 mysql mysql 4096 Jul 18 20:14 plugin
建软连接
[root@localhost lib]# ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib/
3、设置数据库默认编码
修改my.cnf
[mysqld] character-set-server=utf8 [mysql] default-character-set=utf8 [client] default-character-set=utf8
重启服务。
“set names utf8”