MySQL通常有三种安装方式:
专用软件包管理器 deb , rpm(yum)
通用二进制包安装
源码编译安装
下面说一下几种安装方法差异:
RPM | 二进制 | 源码 | |
优点 | 安装简单、方便,适合初学者 | 1、安装简单 2、可以安装在任意路径 3、一台服务器可以安装多个MySQL |
1、可根据实际情况,进行定制,最灵活 2、性能最好 3、一台服务器可以安装多个MySQL |
缺点 | 安装路径以及配置不灵活,默认路径不能修改,一台服务器只能安装一个MySQL | 1、已经经过编译,性能可能不如源码编译的好 2、无法定制编译参数 |
1、安装过程复杂 2、编译时间长 |
目录 | /usr/bin /usr/sbin /var/lib/mysql /usr/share/doc/packages /usr/include/mysql /usr/include/lib /usr/share/mysql /var/lib/mysql |
bin data docs include lib scripts |
请查看源码 |
当然,最适合就是最好的方式 |
这里, 我们仅对源码编译安装方式进行讲解。我们先看一下MySQL源代码的目录结构:
|-- BUILD # 针对各平台检测脚本 |-- Docs # 文档 |-- client # mysql客户端程序 |-- cmake |-- cmd-line-utils |-- dbug |-- extra |-- include |-- libevent |-- libmysql |-- libmysqld |-- libservices |-- man |-- mysql-test |-- mysys |-- mysys_ssl |-- packaging |-- plugin |-- regex |-- scripts # 一些脚本 |-- sql # mysql服务端程序 |-- sql-bench |-- sql-common |-- storage |-- strings |-- support-files # 额外的配置文件 |-- tests |-- unittest |-- vio |-- win `-- zlib
差异
在MySQL 5.1.x 以前,使用 ./configure , make , make install 三部曲进行编译安装。
在MySQL 5.5 版本之后,MySQL自动化建构工具从GNU Autotools换成了跨平台的 Cmake,编译和配置和原来的 ./configure 有些不同。
cmake 的重要特性之一是其独立于源码(out-of-source)的编译功能,即编译工作可以在另一个指定的目录中而非源码目录中进行,这可以保证源码目录不受任何一次编译的影响,因此在同一个源码树上可以进行多次不同的编译,如针对不同平台进行编译。
1、安装必要的编译环境
#通过rpm -qa | grep name 的方式验证以下软件包是否已全部安装 gcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel* libgcrypt* libtool* # 如果缺少相关的软件包,可通过yum -y install 的方式在线安装或者直接从系统安装光盘中找到,然后通过 rpm -ivh 安装 # yum -y install gcc gcc-c++ autoconf automake zlib* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make ### 或者说是更粗暴的方式 # yum -y groupinstall "Development tools" ########################################## ### 然后安装以下包, 可以避免后面出现的错误 # yum -y install ncurses-devel
2、安装cmake
我还是建议yum安装cmake,可以省不少力气。这里也提供源码编译安装的过程。
# yum -y install cmake 或者 ## 源码编译安装 cmake [root@mysql src]# tar xf cmake-2.8.11.2.tar.gz [root@mysql src]# cd cmake-2.8.11.2 [root@mysql cmake-2.8.11.2]# ls bootstrap CTestCustom.cmake.in ChangeLog.manual CTestCustom.ctest.in ChangeLog.txt DartConfig.cmake CMakeCPack.cmake DartLocal.conf.in CMakeCPackOptions.cmake.in Docs CMakeGraphVizOptions.cmake doxygen.config CMakeLists.txt Example CMakeLogo.gif Modules cmake_uninstall.cmake.in Readme.txt CompileFlags.cmake Source configure Templates Copyright.txt Tests CTestConfig.cmake Utilities [root@mysql cmake-2.8.11.2]# ./bootstrap [root@mysql cmake-2.8.11.2]# make && make install
3、创建mysql用户和组
# groupadd -r mysql # useradd -r -g mysql -M -s /sbin/nologin mysql
4、创建mysql数据目录(建议独立分区,且为逻辑卷)
这里,我创建 /mydata/data 目录
# mkdir -pv /mydata/data # chown -R mysql:mysql /mydata/data # ls -l /mydata total 4 drwxr-xr-x 2 mysql mysql 4096 Jul 10 07:17 data
5、编译安装: 从configure 更换为 cmake
我相信大多数人都已经习惯之前的configure方式,并且所使用的参数也是比较人性化的。换成cmake之后,可能带来不少麻烦。
还好,MySQL官方网站提供了二者参数对照表,我们可以尽可能从configure切换到 cmake。
configure与cmake参数对照:
http://dev.mysql.com/doc/internals/en/autotools-to-cmake.html
说明:cmake指定编译选项的方式不同于make,其实现方式对比如下
./configure 对应的是 cmake . (cmake . 点)
./configure --help 对应的是 cmake . -LH 或者是 ccmake .
# 查看mysql源码包目录的BUILD-CMAKE # vi BUILD-CMAKE Listing configuration parameters --------------------------------------------------------------- shell> cmake -L Gives a brief overview of important configuration parameters (dump to stdout) shell> cmake -LH Does the same but also provides a short help text for each parameter. shell> cmake -LAH Dumps all config parameters (including advanced) to the stdout.
编译安装:
# tar xf mysql-5.5.38.tar.gz -C /usr/local/ # ln -sv mysql-5.5.38 mysql # cd mysql [root@localhost mysql]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/mydata/data \ -DSYSCONFDIR=/etc \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_SSL:STRING=bundled \ -DWITH_ZLIB:STRING=bundled \ -DWITH_LIBWRAP=0 \ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ -DMYSQL_TCP_PORT=3306 \ -DMYSQL_USER=mysql \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci
哎呀,我。。报错了,”Curses library not found“.
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH) CMake Error at cmake/readline.cmake:83 (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:118 (FIND_CURSES) cmake/readline.cmake:214 (MYSQL_USE_BUNDLED_READLINE) CMakeLists.txt:361 (MYSQL_CHECK_READLINE) -- Configuring incomplete, errors occurred!
我们根据提示, 知道缺少ncurses-devel包,那么这就好办了,yum 安装即可
[root@localhost mysql]# yum -y install ncurses-devel
下面我们再次重新编译一下,可能还会报同样的错误,不要着急,遇到错误才能够学到东西,我们要仔细查看“报错信息”。人家已经说得非常清楚了,(-__-)b 都怪自己没有仔细看:
我们在多次运行cmake有个文件我们需要删除,删除当前目录下CMakeCache.txt文件并重新编译,再次运行cmake命令就可以正常执行了!
[root@localhost mysql]# rm -f CMakeCache.txt # 再次使用上述的 cmake 指令, 重新执行
如果环境检查没有问题, 那么下面就可以真正执行编译过程以及安装了,还是熟悉的: make && make install 。
[root@localhost mysql]# make && make install
这是一个非常漫长的过程,大概需要30分钟左右,看你机器的配置,在make和make install的时候可以看到进度百分比,感觉这一点比configure方式要人性化。
那么这里我们就来详细看看具体的编译选项
6、编译选项
指定安装文件的安装路径时常用的选项
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql # 指定安装路径(默认的就是/usr/local/mysql) -DMYSQL_DATADIR=/data/mysql # mysql的数据文件路径 -DSYSCONFDIR=/etc # 配置文件目录
编译过程中启用其他存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 # 使用INNOBASE存储引擎 -DWITH_ARCHIVE_STORAGE_ENGINE=1 # 常应用于日志记录和聚合分析,不支持索引 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 # 黑洞存储引擎
编译过程中取消一些存储引擎
-DWITHOUT__STORAGE_ENGINE=1 示例如下: -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_FEDERATED_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGINE=1
编译进过程中功能启用的指令介绍
-DWITH_READLINE=1 # 支持批量导入mysql数据 -DWITH_SSL=system # mysql支持ssl会话,实现基于ssl的数据复 -DWITH_ZLIB=system # 压缩库 -DWITH_LIBWRAP=0 # 是否可以基于WRAP实现访问控制
其他功能指令
-DMYSQL_TCP_PORT=3306 # 默认端口 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock # 默认套接字文件路径 -DENABLED_LOCAL_INFILE=1 # 是否启用LOCAL_INFILE功能 -DEXTRA_CHARSETS=all # 是否支持额外的字符集 -DDEFAULT_CHARSET=utf8 # 默认编码机制 -DDEFAULT_COLLATION=utf8_general_ci # 设定默认语言的排序规则 -DWITH_DEBUG=0 # DEBUG功能设置 -DENABLE_PROFILING=1 # 性能分析功能是否启用
编译的参数可以参考http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html。
MySQL 安装完成之后的目录结构:
* bin Binary files for the server binaries and client programs such as the mysql command-lien client, mysqldump, and mysql admin * data Databases and database data and index files * include Header files * lib Compiled libraries * man Man pages * mysql-test Test suite for testing MySQL Server * scripts Contains the script used to initialize a new installation * share Language support for messages such as errors * sql-bench Benchmarking test program files * support-files Example configurations and scripts for log rotation and staring MySQL Server
7、MySQL服务启动脚本 及 配置文件
为了方便管理,MySQL官方提供给我们一些脚本:
# mysql 安装目录 # cd /usr/local/mysql # 拷贝配置文件 [root@localhost mysql]# cp support-files/my-medium.cnf /etc/my.cnf # 拷贝服务启动脚本 [root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld # 给脚本赋予可执行权限 [root@localhost mysql]# chmod +x /etc/init.d/mysqld # 加入SysV [root@localhost mysql]# chkconfig --add mysqld # 开机启动 [root@localhost mysql]# chkconfig mysqld on
8、初始化配置表(用户表、权限表等)
Initial Configuration(非常重要的一步)
After installation, mysqld must be initialized and configured
mysql_install_db — Initialize MySQL Data Directory
mysql_install_db initializes the MySQL data directory and creates the system tables that it contains, if they do not exist. mysql_install_db is a shell script and is available only on Unix platforms. (As of MySQL 5.6, mysql_install_db is a Perl script and can be used on any system with Perl installed.)
当MySQL的系统库发生故障或需要新增一个实例,就需要进行初始化。
[root@localhost mysql]# /usr/local/mysql/scripts/mysql_install_db \ --basedir=/usr/local/mysql \ --datadir=/mydata/data \ --user=mysql
额, 不知道什么情况, mysql_install_db 竟然没有可执行权限。
[root@localhost mysql]# chmod +x /usr/local/mysql/scripts/mysql_install_db # 然后重新执行 ### 或者 [root@localhost mysql]# bash /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/mydata/data --user=mysql --basedir:该参数指定了安装 MySQL 的安装路径,填写全路径可以解决相对路径所造成的问题。 --datadir:该参数指定了 MySQL 的数据库文件放在什么路径下。数据库文件即我们常说的 MySQL data 文件 To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/local/mysql/bin/mysqladmin -u root password 'new-password' /usr/local/mysql/bin/mysqladmin -u root -h mysql password 'new-password' Alternatively you can run: /usr/local/mysql/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd . ; /usr/local/mysql/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com New default config file was created as /usr/local/mysql/my.cnf and will be used by default by the server when you start it. You may edit this file to change server settings WARNING: Default config file /etc/my.cnf exists on the system This file will be read by default by the MySQL server If you do not want to use this, either remove it, or use the --defaults-file argument to mysqld_safe when starting the server
注意:为了安全,我们把mysql解压目录属主、属组改为root
[root@localhost mysql]# chown -R root:root mysql-5.5.38/
注:在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索"$basedir/my.cnf",在本例中就是 /usr/local/mysql/my.cnf,这是新版MySQL的配置文件的默认位置!
注意:在CentOS 6.4版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。
在使用"yum update"更新系统后,需要检查下/etc目录下是否会多出一个my.cnf,如果多出,将它重命名成别的。否则,MySQL将使用这个配置文件启动,可能造成无法正常启动等问题。
9、修改配置文件 /etc/my.cnf
# The following options will be passed to all MySQL clients [client] #password = your_password port = 3306 socket = /tmp/mysql.sock # Here follows entries for some specific programs # The MySQL server [mysqld] user = mysql port = 3306 socket = /tmp/mysql.sock basedir = /usr/local/mysql datadir = /mydata/data pid-file = /mydata/data/mysqld.pid ft_min_word_len = 4 max_allowed_packet = 32M character-set-server = utf8 skip-name-resolve
10、启动mysql服务
[root@localhost mysql]# service mysqld start Starting MySQL... SUCCESS! # 做一些基础安全配置,对MySQL进行安全设置(包括数据库密码以及相关的库权限设置) [root@localhost mysql]# bin/mysql_secure_installation # 根据提示选择 [Y/n] <-------此处省略---------> #这里是运行后相关的提示信息 Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. You already have a root password set, so you can safely answer 'n'. Change the root password? [Y/n] y #(设置MySQL管理员root密码) New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! Remove anonymous users? [Y/n] y #(移除匿名用户,选择Y) ... Success! <-------此处省略---------> Disallow root login remotely? [Y/n] y #(移除管理员远程访问权限,选择Y) ... Success! <-------此处省略---------> Remove test database and access to it? [Y/n] y #(移除test测试数据库,选择Y) <-------此处省略---------> Reload privilege tables now? [Y/n] y #(刷新数据库权限,选择Y) ... Success! # 测试是否启动成功,查看3306端口 [root@localhost mysql]# netstat -tunlp | grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 24533/mysqld # 登录mysql [root@localhost mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.5.38-log Source distribution Copyright (c) 2000, 2014, 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初始化完成后,会默认启用5个空密码用户(3个root用户,2个匿名用户),存在安全性隐患(可以通过mysql_secure_installation 进行处理)。下面简单介绍一下用户管理相关的知识。
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.3.%' IDENTIFIED BY '123456' WITH GRANT OPTION; # 创建一个具有root用户权限的用户(admin),密码为123456 mysql> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY '123456'; Query OK, 0 rows affected (0.00 sec) mysql> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1' IDENTIFIED BY '123456'; Query OK, 0 rows affected (0.00 sec) ##删除本机匿名帐号 /usr/local/mysql/bin/mysql -uroot -p 'new-password' mysql>use mysql; # 选择系统数据库mysql mysql>select Host,User,Password from user; # 查看所有用户 mysql>delete from user where user=''; mysql>flush privileges; mysql>select Host,User,Password from user; # 确认匿名用户是否已全部删除 mysql>exit; #或者 mysql> DROP USER ''@'localhost'; ## 用户密码修改方式: 3种 1、# mysqladmin -u USERNAME -h HOSTNAME password 'NEW_PASS' -p 2、mysql> SET PASSWORD FOR 'USERNAME'@'HOST' = PASSWORD('NEW_PASS'); 3、mysql> UPDATE mysql.user SET PASSWORD=PASSWORD('NEW_PASS') WHERE CONDITION; mysql> FLUSH PRIVILEGES; mysql> UPDATE mysql.user SET PASSWORD=PASSWORD('123456') WHERE user='root'; mysql> FLUSH PRIVILEGES; # 必须刷新权限
11、配置防火墙
防火墙的3306端口默认没有开启,若要远程访问,需要开启这个端口
打开/etc/sysconfig/iptables , 添加如下一行(注意先后顺序)
-A INPUT -m state --state NEW,ESTABLISHED -p --dport 3306 -j ACCEPT
接下来,我们还需要做一些额外的工作:
1、将mysql的bin目录加入PATH 环境变量
[root@localhost mysql]# vim /etc/profile.d/mysql.sh export PATH=$PATH:/usr/local/mysql/bin [root@localhost mysql]# . /etc/profile.d/mysql.sh # 看一下是否成功 [root@localhost mysql]# echo $PATH /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin
2、将mysql的man手册加入到man的path
[root@localhost mysql]# vim /etc/man.config # 新增一行 MANPATH /usr/local/mysql/man
3、mysql的库文件
[root@localhost mysql]# vim /etc/ld.so.conf.d/mysql.conf /usr/local/mysql/lib/ [root@localhost mysql]# ldconfig -v /usr/local/mysql/lib: libmysqlclient.so.18 -> libmysqlclient_r.so.18.0.0 /usr/lib/mysql: libmysqlclient.so.16 -> libmysqlclient.so.16.0.0 libmysqlclient_r.so.16 -> libmysqlclient_r.so.16.0.0
4、mysql的头文件
[root@localhost mysql]# ln -sv /usr/local/mysql/include /usr/include/mysql `/usr/include/mysql' -> `/usr/local/mysql/include'
快速安装指南:
【本文档所介绍的内容适用于公司测试/生产等常见的MySQL数据库环境部署】 一:环境部署前准备: 1.1相关软件以及系统 系统要求:Centos 6.6 (64位) 相关中间件: mysql-5.6.23 1.2相关系统依赖包安装检查准备 1.2.1 检查系统自带mysql是否安装 # rpm -qa | grep mysql 如有安装,请使用以下命令卸载相关程序 # yum remove mysql 1.2.2 安装系统相关的编译环境:mysql编译前需要的依赖包 # yum installwget gcc gcc-c++ cmake ncurses ncurses-devel bison bison-devel libaio-devel perl file patch mlocate flex diffutils readline-devel libcap-devel autoconf automake libgcrypt* libtool* openssl openssl-devel 二:MySQL环境部署正式安装: 2.1编译安装MySQL MySQL从5.5版本开始,通过./configure进行编译配置方式已经被取消,取而代之的是cmake工具编译。 因此,我们首先要在系统中源码编译安装cmake工具,安装cmake时可以源码安装也可以yum 安装,这里采用的yum形式安装cmake 2.1.1 mysql安装前准备(安装mysql前先需要添加相关的mysql运行账号及相关安装目录和权限) <--添加mysql运行账号--> # groupadd mysql #添加mysql服务组账号; # useradd -g mysql -M -s /sbin/nologin mysql #添加mysql服务服务账号,设置不登陆系统; <--添加mysql程序相关目录--> # mkdir -p /usr/local/mysql #创建mysql安装目录; # mkdir -p /mydata/data #创建mysql数据存放目录; 2.1.2编译安装mysql(默认包放在/root目录下,包统一解压到/usr/local/src) # tar -zxvf mysql-5.6.23.tar.gz -C /usr/local/src/ # cd /usr/local/src/mysql-5.6.23/ # cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DEXTRA_CHARSETS=all \ -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 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DMYSQL_USER=mysql \ -DMYSQL_TCP_PORT=3306 \ -DSYSCONFDIR=/etc \ -DWITH_SSL=yes # make && make install 《提示:如果以上编译编译失败的话,重新编译需要再执行以下命令,并清除相关文件,内容如下: # make clean # rm -f CMakeCache.txt 2.1.3 给mysql相关目录设置属主权限 # chown -R mysql:mysql /usr/local/mysql #设置mysql安装目录的属主; # chown -R mysql:mysql /mydata/data #设置mysql数据存放目录的属主; 2.1.4 初始化mysql数据库准备 # cd /usr/local/mysql/ //设置mysql安装目录的属主; # scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/mydata/data --user=mysql #初始化mysql数据库; 2.1.5 添加mysql数据库配置文件模板 # cd /usr/local/mysql/ #进入到安装目录拷贝数据库配置样例模板; # cp support-files/my-medium.cnf /etc/my.cnf #这里样例模板可以是生产也可以是开发; 2.1.6 添加mysql服务启动到系统服务里,并优化mysql命令调用 <--添加mysql服务启动到系统服务,并开机自启动--> # cd /usr/local/mysql/ # cp support-files/mysql.server /etc/init.d/mysqld #拷贝mysql服务脚本到系统; # vim /etc/init.d/mysqld 找到如下内容并添加相关路径 basedir=/usr/local/mysql #mysql安装目录; datadir=/mydata/data #mysql数据存放目录; # chkconfig -add mysqld #添加mysql服务到系统服务; # chkconfig --level 235 mysqld on #设置mysql开机自启动; <--优化mysql命令调用--> 修改/etc/profile文件,在文件末尾添加 # PATH=/usr/local/mysql/bin:$PATH # export PATH # wq! //保存 # source /etc/profile 2.1.7 启动mysql服务,并设置管理员账号密码 # service mysqld start #启动MySQL数据库服务 # mysql_secure_installation #对MySQL进行安全设置(包括数据库密码以及相关的库权限设置) <-------此处省略---------> //这里是运行后相关的提示信息 Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. You already have a root password set, so you can safely answer 'n'. Change the root password? [Y/n] y (设置MySQL管理员root密码) New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! Remove anonymous users? [Y/n] y (移除匿名用户,选择Y) ... Success! <-------此处省略---------> Disallow root login remotely? [Y/n] y (移除管理员远程访问权限,选择Y) ... Success! <-------此处省略---------> Remove test database and access to it? [Y/n] y (移除test测试数据库,选择Y) <-------此处省略---------> Reload privilege tables now? [Y/n] y (刷新数据库权限,选择Y) ... Success! Cleaning up... 三:测试数据库是否可以正常工作 # mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 29269 Server version: 5.5.43-log Source distribution Copyright (c) 2000, 2015, 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已经正常运行,MySQL环境编译安装ok!
附录:
MySQL 5.5 编译参数说明
从mysql5.5起,mysql源码安装开始使用cmake。下面是 mysql 5.5 与以前的参数对照:
configure Command CMake Command
./configure cmake .
./configure –help cmake . -LH or ccmake .
参考:http://www.oicto.com/mysql-cmake/
参数说明:
红色为推荐参数(当然也要根据你的需求来制定)
绿色为可用参数
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录
-DMYSQL_DATADIR=/usr/local/mysql/data //数据库存放目录
-DWITH_MYISAM_STORAGE_ENGINE=1 //安装myisam存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 //安装innodb存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 //安装archive存储引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 //安装blackhole存储引擎
-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
-DDEFAULT_CHARSET=utf8 //使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci //校验字符
-DEXTRA_CHARSETS=all //安装所有扩展字符集
-DMYSQL_TCP_PORT=3306 //MySQL监听端口
-DMYSQL_USER=mysql //MySQL用户名
其他参数:
-DWITH-EMBEDDED_SERVER=1 //编译成embedded MySQL library (libmysqld.a)
-DSYSCONFDIR=/etc //MySQL配辑文件
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock //Unix socket 文件路径
-DWITH_READLINE=1 //快捷键功能
-DWITH_SSL=yes //SSL
-DWITH_MEMORY_STORAGE_ENGINE=1 //安装memory存储引擎
-DWITH_FEDERATED_STORAGE_ENGINE=1 //安装frderated存储引擎
-DWITH_PARTITION_STORAGE_ENGINE=1 //安装数据库分区
-DINSTALL_PLUGINDIR=/usr/local/mysql/plugin //插件文件及配置路径
BUILD_CONFIG 采用官方发行版一致的编译参数
CMAKE_BUILD_TYPE 指定产品编译说明信息 RelWithDebInf
CMAKE_INSTALL_PREFIX 指定MySQL安装路径 /usr/local/mysql
CPACK_MONOLITHIC_INSTALL是否建立单个安装包文件 OFF
DEFAULT_CHARSET MYSQL 默认字符集 latin1
DEFAULT_COLLATION MYSQL 默认排序字符集 latin1_swedish_ci
ENABLE_DEBUG_SYNC 是否启用同步调试功能 ON
ENABLE_DOWNLOADS 是否下载可选文件 OFF
ENABLE_DTRACE 是否包含 DTrace 支持
ENABLE_GCOV 是否包含 Gcov 支持 5.5.14
ENABLED_LOCAL_INFILE 是否启用本地 LOAD DATA INFILE OFF
ENABLED_PROFILING 是否启用代码查询分析 ON
INSTALL_BINDIR MySQL 主执行文件目录 PREFIX/bin
INSTALL_DOCDIR 文档安装路径 PREFIX/docs
INSTALL_DOCREADMEDIR 自述文件目录 PREFIX
INSTALL_INCLUDEDIR 头文件目录 PREFIX/include
INSTALL_INFODIR 关于信息文件目录 PREFIX/docs
INSTALL_LAYOUT 选择预定义的安装 STANDALONE
INSTALL_LIBDIR 库文件目录 PREFIX/lib
INSTALL_MANDIR 手册页面目录 PREFIX/man
INSTALL_MYSQLSHAREDIR 共享数据目录 PREFIX/share
INSTALL_MYSQLTESTDIR mysql-test 目录 PREFIX/mysql-test
INSTALL_PLUGINDIR 插件目录 PREFIX/lib/plugin
INSTALL_SBINDIR 服务器超级用户执行文件目录 PREFIX/bin
INSTALL_SCRIPTDIR 脚本目录 PREFIX/scripts
INSTALL_SHAREDIR aclocal/mysql.m4 安装目录 PREFIX/share
INSTALL_SQLBENCHDIR sql-bench 性能测试工具目录 PREFIX
INSTALL_SUPPORTFILESDIR 扩展支持文件目录 PREFIX/support-files
MYSQL_DATADIR 数据库存放目录
MYSQL_MAINTAINER_MODE 是否启用MySQL的维护环境 OFF
MYSQL_TCP_PORT TCP/IP 端口号 3306
MYSQL_UNIX_ADDR Unix Socket 套接字文件 /tmp/mysql.sock
SYSCONFDIR 选项配置文件目录
WITH_COMMENT 编译环境发表评论
WITH_DEBUG 是否包括调试支持 OFF
WITH_EMBEDDED_SERVER 是否要建立嵌入式服务器 OFF
WITH_xxx_STORAGE_ENGINE 静态编译xxx 存储引擎到服务器
WITH_EXTRA_CHARSETS 额外的字符集,包括 all
WITH_LIBWRAP 是否包括支持libwrap(TCP包装) OFF
WITH_READLINE 使用捆绑的readline OFF
WITH_SSL 是否支持SSL no
WITH_ZLIB 是否支持Zlib system
WITHOUT_xxx_
MySQL 5.5.30服务器端优化 /etc/my.cnf配置文件 [client] port = 3306 socket = /tmp/mysql.sock [mysqld] #### mise #### user = mysql port = 3306 socket = /tmp/mysql.sock basedir = /data/mysql datadir = /data/mysql/data pid-file=/data/mysql/mysqld.pid #default-storage-engine = MYISAM ft_min_word_len = 4 max_allowed_packet = 32M character-set-server = utf8 skip-name-resolve #### performance #### open_files_limit = 10240 max_connections = 800 max_connect_errors = 6000 thread_stack = 192K transaction_isolation = REPEATABLE-READ tmp_table_size = 256M max_heap_table_size = 256M slow_query_log long_query_time = 1 log_slow_queries=/data/mysql/slow-log.log #### log #### log-error=/data/mysql/mysqld.err back_log = 500 log-bin=mysql-bin max_binlog_cache_size = 8M max_binlog_size = 512M binlog_format=mixed expire_logs_days = 7 #### buffer && cache #### read_buffer_size = 10M read_rnd_buffer_size = 32M sort_buffer_size = 2M join_buffer_size = 2M thread_cache_size = 300 thread_concurrency = 8 query_cache_size = 64M query_cache_limit = 4M binlog_cache_size = 4M table_open_cache = 2048 key_buffer_size = 32M bulk_insert_buffer_size = 64M #### myisam #### myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 myisam_recover #### innodb #### innodb_additional_mem_pool_size = 16M innodb_buffer_pool_size = 4G innodb_data_file_path = ibdata1:1024M:autoextend innodb_write_io_threads = 8 innodb_read_io_threads = 8 innodb_thread_concurrency = 16 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 16M innodb_log_file_size = 150M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 60 innodb_flush_method = O_DIRECT #### replication #### replicate-ignore-db = mysql replicate-ignore-db = test replicate-ignore-db = information_schema server-id = 1 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash [myisamchk] key_buffer_size = 32M sort_buffer_size = 32M read_buffer = 8M write_buffer = 8M [mysqlhotcopy] interactive-timeout [mysqld_safe] open-files-limit = 8196