mysql安装一 --- 源码包安装
1.登陆http://www.mysql.com/ 或者 www.oracle.com
2.
3.
4.
上面如果不能加载,禁用代理软件
5.
6.
7.
8.
9.上传
10.md5校验安装包的完整性
[root@db2 ~]# md5sum ./mysql-5.6.26.tar.gz
733e1817c88c16fb193176e76f5b818f ./mysql-5.6.26.tar.gz
与上面的md5对照,如果一致说明安装包完整无缺
11.解压
[root@db2 ~]# tar -xzvf mysql-5.6.26.tar.gz
源码目录说明:源码包目录.md
正式安装
1.安装cmake
下载地址:http://www.cmake.org/ 或者 http://yunpan.cn/cHgpTUaYRqjnc 访问密码 384d
tar -xzvf cmake-3.3.1.tar.gz
cd cmake-3.3.1
./configure
make
make install
需要安装gcc
yum install gcc
yum install gcc-c++
2.创建mysql安装目录和数据文件目录
[root@db2 ~]# mkdir -p /usr/local/mysql
[root@db2 ~]# mkdir -p /usr/local/mysql/data
3.创建用户和组
groupadd mysql
useradd -r -g mysql mysql
4.安装mysql
tar -xzvf mysql-5.6.26.tar.gz
[root@db2 ~]# cd mysql-5.6.26
cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
[root@db2 mysql-5.6.26]# make && make install
参数说明:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录
-DINSTALL_DATADIR=/usr/local/mysql/data //数据库存放目录
-DDEFAULT_CHARSET=utf8 //使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci //校验字符
-DEXTRA_CHARSETS=all //安装所有扩展字符集
-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
编译的参数可以参考http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html
** 注意事项:**
重新编译时,需要清除旧的对象文件和缓存信息。
# make clean
# rm -f CMakeCache.txt
# rm -rf /etc/my.cnf
5.配置
[root@db2 ~]# chown -R mysql:mysql /usr/local/mysql
[root@db2 ~]# cp mysql-5.6.26/support-files/my-small.cnf /usr/local/mysql/my.cnf
编辑my.cnf
在mysqld标签下添加如下内容:
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
(1)初始化配置
进入安装路径,执行初始化配置脚本,创建系统自带的数据库和表
[root@db2 ~]# cd /usr/local/mysql/
[root@db2 mysql]# scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
(2)设置环境变量
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
export PATH
. .bash_profile
6.启动服务
(1)手动启动mysql服务
[root@ rhel5~]# cd /usr/local/mysql
[root@ rhel5 mysql]# ./bin/mysqld_safe --user=mysql & //启动MySQL,但不能停止
启动日志写在此文件下:/usr/local/mysql/data/localhost.err
[root@db2 bin]# ps -ef | grep mysql
root 22979 58621 0 22:56 pts/1 00:00:00 /bin/sh ./bin/mysqld_safe --user=mysql
mysql 23069 22979 0 22:56 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/db2.err --pid-file=/usr/local/mysql/data/db2.pid
root 23119 58621 0 22:57 pts/1 00:00:00 grep mysql
关闭MySQL服务
[root@db2 mysql]# ./bin/mysqladmin -u root -p shutdown
Enter password:
150917 23:03:57 mysqld_safe mysqld from pid file /usr/local/mysql/data/db2.pid ended
[1]+ Done ./bin/mysqld_safe --user=mysql
//这里MySQL的root用户还没有配置密码,所以为空值。需要输入密码时,直接点回车键即可。
(2)设置自动启动mysql
[root@db2 mysql]# cp support-files/mysql.server /etc/init.d/mysql
[root@db2 mysql]# chkconfig mysql on
[root@db2 mysql]# service mysql start
Starting MySQL. [ OK ]
错误
[root@db2 mysql-5.6.26]# cmake .
-- Running cmake version 3.3.1
-- Could NOT find Git (missing: GIT_EXECUTABLE)
-- MySQL 5.6.26
-- Packaging as: mysql-5.6.26-Linux-i686
-- Could NOT find Threads (missing: Threads_FOUND)
-- Could NOT find Threads (missing: Threads_FOUND)
-- Check if the system is big endian
-- Searching 16 bit integer
CMake Error at /usr/local/share/cmake-3.3/Modules/TestBigEndian.cmake:51 (message):
no suitable type found
Call Stack (most recent call first):
configure.cmake:628 (TEST_BIG_ENDIAN)
CMakeLists.txt:398 (INCLUDE)
-- Configuring incomplete, errors occurred!
See also "/root/mysql-5.6.26/CMakeFiles/CMakeOutput.log".
See also "/root/mysql-5.6.26/CMakeFiles/CMakeError.log".
解决办法:
删除目录,重新解压mysql包
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:85 (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:128 (FIND_CURSES)
cmake/readline.cmake:202 (MYSQL_USE_BUNDLED_EDITLINE)
CMakeLists.txt:409 (MYSQL_CHECK_EDITLINE)
-- Configuring incomplete, errors occurred!
See also "/root/mysql-5.6.26/CMakeFiles/CMakeOutput.log".
See also "/root/mysql-5.6.26/CMakeFiles/CMakeError.log".
解决:
yum install ncurses-devel
rm -rf CMakeCache.txt
重新执行
cmake .
[ 50%] Building C object sql/CMakeFiles/sql.dir/__/sql-common/my_time.c.o
[ 50%] Building C object sql/CMakeFiles/sql.dir/__/sql-common/my_user.c.o
[ 51%] Building C object sql/CMakeFiles/sql.dir/__/sql-common/pack.c.o
[ 51%] Building CXX object sql/CMakeFiles/sql.dir/__/sql-common/client_authentication.cc.o
[ 51%] Building CXX object sql/CMakeFiles/sql.dir/event_data_objects.cc.o
[ 51%] Building CXX object sql/CMakeFiles/sql.dir/event_db_repository.cc.o
[ 51%] Building CXX object sql/CMakeFiles/sql.dir/event_parse_data.cc.o
[ 51%] Building CXX object sql/CMakeFiles/sql.dir/event_queue.cc.o
[ 51%] Building CXX object sql/CMakeFiles/sql.dir/event_scheduler.cc.o
[ 51%] Building CXX object sql/CMakeFiles/sql.dir/events.cc.o
[ 51%] Building CXX object sql/CMakeFiles/sql.dir/mysqld.cc.o
[ 51%] Building CXX object sql/CMakeFiles/sql.dir/sql_client.cc.o
[ 51%] Linking CXX static library libsql.a
/usr/bin/ar: CMakeFiles/sql.dir/rpl_handler.cc.o: No such file or directory
make[2]: *** [sql/libsql.a] Error 1
make[1]: *** [sql/CMakeFiles/sql.dir/all] Error 2
make: *** [all] Error 2
服务启动失败:
或者
解决:
注:在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索”$basedir/my.cnf”,在本例中就是 /usr/local/mysql/my.cnf,这是新版MySQL的配置文件的默认位置!
注意:在rhel 6.4版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。
在使用”yum update”更新系统后,需要检查下/etc目录下是否会多出一个my.cnf,如果多出,将它重命名成别的。否则,MySQL将使用这个配置文件启动,可能造成无法正常启动等问题。
mv /etc/my.cnf /etc/my.cnf.bak