注意:在虚拟机cmake安装mysql5.5.32时,将虚拟机内存调至2G。(原创,请勿转载!)
一、安装MySQL依赖包
[root@cmake ~]# yum install pcre pcre-devel openssl openssl-devel gcc-c++ ncurses-devel -y
二、安装cmake
官网:https://cmake.org/download/
[root@cmake eleven]# mkdir /home/eleven/tools
[root@cmake eleven]# cd /home/eleven/tools/
[root@cmake tools]# wget https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz
[root@cmake tools]# tar xf cmake-3.9.0.tar.gz
[root@cmake tools]# cd cmake-3.9.0
[root@cmake cmake-3.9.0]# ./configure
[root@cmake cmake-3.9.0]# gmake
[root@cmake cmake-3.9.0]# gmake install
[root@cmake cmake-3.9.0]# /usr/local/bin/cmake --version
cmake version 3.9.0
CMake suite maintained and supported by Kitware (kitware.com/cmake).
#cmake安装结束,也可以把gmake,gmake install改为make, make install。
#cmake命令默认路径/uer/local/bin/camke,编译mysql用全路径即可。
# /usr/local/bin/cmake --version,查看版本,说明cmake安装正常。
++++++++++++++++++++++++++++++++++
cmake的一些错误做法:
#将cmake命令复制到/usr/bin。
#使用which camke命令查看。
#使用cmake命令编译mysql,都会提示出错。
#必须用全路径 /usr/local/bin/cmake。
错误如下:
[root@cmake cmake-3.9.0]# which cmake
/usr/bin/which: no cmake in (/sbin:/bin:/usr/sbin:/usr/bin)
[root@cmake cmake-3.9.0]# cp /usr/local/bin/cmake /usr/bin/
[root@cmake cmake-3.9.0]# which cmake
/usr/bin/cmake
[root@cmake cmake-3.9.0]# cmake --version
CMake Error: Could not find CMAKE_ROOT !!!
CMake has most likely not been installed correctly.
Modules directory not found in
/usr/share/cmake-3.9
cmake version 3.9.0
CMake suite maintained and supported by Kitware (kitware.com/cmake).
三、cmake编译安装MySQL5.5.32
1、上传mysql5.5.32.tar.gz
[root@cmake tools]# rz
[root@cmake tools]# tar xf mysql-5.5.32.tar.gz
[root@cmake tools]# useradd mysql -s /sbin/nologin -M
[root@cmake tools]# cd mysql-5.5.32
[root@cmake mysql-5.5.32]# /usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \
-DMYSQL_DATADIR=/application/mysql-5.5.32/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0 \
-DDEFAULT_CHARSET=utf8 \ #不需要此行
-DDEFAULT_COLLATION=utf8_general_ci \ #不需要此行
为了让默认字符集是什么,就不指定字符集了。
删掉指定字符那两行后,就是默认字符集了,删掉后再编译安装。
[root@cmake mysql-5.5.32]# make
[root@cmake mysql-5.5.32]# make install
[root@cmake mysql-5.5.32]# ln -s /application/mysql-5.5.32/ /application/mysql
[root@cmake mysql-5.5.32]# cp support-files/my-small.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y
[root@cmake mysql-5.5.32]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data/ --user=mysql
[root@cmake mysql-5.5.32]# cp /application/mysql/bin/mysql /usr/local/bin/
#如果提示命令不存在,就把mysql命令复制到/usr/bin/目录下。
[root@cmake mysql-5.5.32]# chown -R mysql.mysql /application/mysql/data/
[root@cmake mysql-5.5.32]# chmod -R 1777 /tmp/
[root@cmake mysql-5.5.32]# cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@cmake mysql-5.5.32]# vim /etc/init.d/mysqld
basedir=/application/mysql
datadir=/application/mysql/data
[root@cmake mysql-5.5.32]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
[root@cmake mysql-5.5.32]# mysql
bash: mysql: command not found
[root@cmake mysql-5.5.32]# cp /application/mysql/bin/mysql /usr/bin
[root@cmake mysql-5.5.32]# mysql
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> drop database test;
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| | cmake |
| root | cmake |
| | localhost |
| root | localhost |
+------+-----------+
6 rows in set (0.00 sec)
mysql> drop user ""@"cmake";
Query OK, 0 rows affected (0.00 sec)
mysql> drop user ""@"localhost";
Query OK, 0 rows affected (0.00 sec)
mysql> drop user "root"@"::1";
Query OK, 0 rows affected (0.00 sec)
mysql> drop user "root"@"cmake";
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
+------+-----------+
2 rows in set (0.00 sec)
mysql> quit;
Bye
[root@cmake tools]# /application/mysql/bin/mysqladmin -u root password 'ele1958'
[root@cmake tools]# mysql -u root -pele1958