本文是采用mysql源码编译方式,编译器使用Cmake。软件需要mysql-5.5.25.tar.gz和cmake-2.8.6.tar.gz,请自行下载。
mysql-5.5.25.tar.gz和cmake-2.8.6.tar.gz
[root@localhost local]# yum install gcc-c++
[root@localhost local]# yum install ncurses-devel
[root@localhost local]# yum install bison
[root@localhost]# tar -zxv -f cmake-2.8.6.tar.gz // 解压压缩包
[root@localhost local]# cd cmake-2.8.6
[root@localhost cmake-2.8.6]# ./configure
[root@localhost cmake-2.8.6]# make
[root@localhost cmake-2.8.6]# make install
用vi在文件/etc/profile文件中增加变量,使其永久有效,
[root@localhost local]# vi /etc/profile
在文件末尾追加以下两行代码:
PATH=/usr/local/cmake-2.8.6/bin:$PATH
export PATH
执行以下代码使刚才的修改生效:
[root@localhost local]# source /etc/profile
用 export 命令查看PATH值
[root@localhost local]# echo $PATH
[root@localhost]# mkdir -p /usr/local/mysql //安装mysql
[root@localhost]# mkdir -p /usr/local/mysql/data //存放数据库
[root@localhost] groupadd mysql
[root@localhost] useradd -r -g mysql mysql
[root@localhost local]# tar -zxv -f mysql-5.5.25.tar.gz //解压
[root@localhost local]# cd mysql-5.5.25
[root@localhost mysql-5.5.25]#
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306
[root@localhost mysql-5.5.25]# make
[root@localhost mysql-5.5.25]# 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 //允许从本地导入数据
注意事项:重新安装时候,需要删除
rm -rf mysql-5.5.25[root@localhost mysql-5.5.25]# cd /usr/local/mysql/
[root@localhost mysql]# ls
bin COPYING data docs include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files
有bin等以上文件的话,恭喜你已经成功安装了mysql。
[root@localhost mysql]# cd /usr/local/mysql //把当前目录中所有文件的所有者设为root,所属组为mysql
[root@localhost mysql]# chown -R root:mysql .
[root@localhost mysql]# chown -R mysql:mysql data
[root@localhost mysql]# cp support-files/my-medium.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
[root@localhost mysql]# cd /usr/local/mysql
[root@localhost mysql]# scripts/mysql_install_db --user=mysql
[root@localhost ~]# vi /root/.bash_profile
在修改PATH=$PATH:$HOME/bin为:
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
[root@localhost ~]# source /root/.bash_profile //使刚才的修改生效
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# ./bin/mysqld_safe --user=mysql & //启动MySQL,但不能停止
mysqladmin -u root -p shutdown //此时root还没密码,所以为空值,提示输入密码时,直接回车即可。
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql
[root@localhost mysql]# service mysql start
Starting MySQL... ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).
启动失败:
我这里是权限问题,先改变权限
[root@localhost mysql]# chown -R mysql:mysql /usr/local/mysql
接着启动服务器
[root@localhost mysql]# /etc/init.d/mysql start
[root@localhost mysql]# mysql -u root mysql
mysql> use mysql;
mysql> desc user;
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; //为root添加远程连接的能力
mysql> update user set Password = password('root') where User='root'; //设置root用户密码
mysql> select Host,User,Password from user where User='root';
mysql> flush privileges;
mysql> exit
[root@localhost mysql]# mysql -u root -p
Enter password:root
[root@localhost]# /etc/rc.d/init.d/iptables stop