linux Mysql 安装及配置

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. [root@localhost mysql-5.7.]# 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= -DWITH_ARCHIVE_STORAGE_ENGINE= -DWITH_BLACKHOLE_STORAGE_ENGINE= -DMYSQL_DATADIR=/data/mysqldb -DMYSQL_TCP_PORT= -DENABLE_DOWNLOADS= ... CMake Error at cmake/boost.cmake: (MESSAGE): You can download it with -DDOWNLOAD_BOOST= -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: (COULD_NOT_FIND_BOOST) CMakeLists.txt: (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= -DWITH_ARCHIVE_STORAGE_ENGINE= -DWITH_BLACKHOLE_STORAGE_ENGINE= -DMYSQL_DATADIR=/data/mysqldb -DMYSQL_TCP_PORT= -DENABLE_DOWNLOADS= -DDOWNLOAD_BOOST= -DWITH_BOOST=/usr/local/boost
  .... 
  CMake Error at cmake/readline.cmake:64 (MESSAGE):
  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".

  See also "/usr/local/src/mysql-5.7.13/CMakeFiles/CMakeError.log".

<<=========================================================================

解决:

(1)安装ncurses-devel

yum -y install ncurses-devel

(2)删除CMakeCache.txt

rm CMakeCache.txt

(3)重新cmake

[root@localhost mysql-5.7.]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=mysql.mysql -DDEFAULT_CHARSET=gbk -DDEFAULT_COLLATION=gbk_chinese_ci -DWITH_INNOBASE_STORAGE_ENGINE= -DWITH_ARCHIVE_STORAGE_ENGINE= -DWITH_BLACKHOLE_STORAGE_ENGINE= -DMYSQL_DATADIR=/data/mysqldb -DMYSQL_TCP_PORT= -DENABLE_DOWNLOADS= -DDOWNLOAD_BOOST= -DWITH_BOOST=/usr/local/boost

==========================================================================>>

[root@localhost mysql-5.7.]# 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连接报错

linux Mysql 安装及配置

mysql> update user set host = '%' where user='root';
Query OK, row affected (0.00 sec)
Rows matched: Changed: Warnings:

重启Mysql服务!

2、安装pdo_mysql扩展

linux Mysql 安装及配置

[root@localhost lib]# cd /usr/local/mysql/lib/
[root@localhost lib]# ll
total
-rw-r--r--. mysql mysql Jul : libmysqlclient.a
lrwxrwxrwx. mysql mysql Jul : libmysqlclient.so -> libmysqlclient.so.
lrwxrwxrwx. mysql mysql Jul : libmysqlclient.so. -> libmysqlclient.so.20.3.
-rwxr-xr-x. mysql mysql Jul : libmysqlclient.so.20.3.
-rw-r--r--. mysql mysql Jul : libmysqld.a
-rw-r--r--. mysql mysql Jul : libmysqlservices.a
drwxr-xr-x. mysql mysql Jul : pkgconfig
drwxr-xr-x. mysql mysql Jul : plugin

建软连接

[root@localhost lib]# ln -s /usr/local/mysql/lib/libmysqlclient.so. /usr/lib/

3、设置数据库默认编码

修改my.cnf

[mysqld]
character-set-server=utf8
[mysql]
default-character-set=utf8
[client]
default-character-set=utf8

重启服务。

linux Mysql 安装及配置

“set names utf8”

上一篇:为什么Visual Studio的安装目录下有名为1033或2052的文件夹?


下一篇:在xcode中用 swift 进行网络服务请求