准备环境
安装mysql依赖包
yum install -y ncurses-devel
[root@localhost ~]# cd tools/
[root@localhost tools]# ls
cmake-2.8.8.tar.gz mysql-5.5.32.tar.gz
安装cmake
[root@localhost tools]# tar -xf cmake-2.8.8.tar.gz
[root@localhost tools]# cd cmake-2.8.8/
[root@localhost cmake-2.8.8]# ./configure
……
-- Configuring done
-- Generating done
-- Build files have been written to: /root/tools/cmake-2.8.8
---------------------------------------------
CMake has bootstrapped. Now run gmake.
[root@localhost cmake-2.8.8]# gmake
[root@localhost cmake-2.8.8]# gmake install
[root@localhost ~]# cd tools/
[root@localhost tools]# tar -xf mysql-5.5.32.tar.gz
[root@localhost tools]# cd mysql-5.5.32/
[root@localhost mysql-5.5.32]# cat install-mysql5.5.32.sh
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-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
[root@localhost mysql-5.5.32]# bash install-mysql5.5.32.sh
[root@localhost mysql-5.5.32]# make -j 4 && make install
初始化配置
[root@localhost ~]# useradd -M -s /sbin/nologin mysql
[root@localhost ~]# cd tools/mysql-5.5.32/
[root@localhost mysql-5.5.32]# cp support-files/my-medium.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
添加启动脚本到系统中
[root@localhost mysql-5.5.32]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql-5.5.32]# chmod 750 /etc/rc.d/init.d/mysqld
环境变量配置
[root@localhost ~]# source /etc/profile
[root@localhost ~]# tail -n 1 /etc/profile
PATH=/usr/local/mysql/bin/:$PATH
初始化数据库
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql
[root@localhost ~]# cd /usr/local/mysql/scripts/
[root@localhost scripts]# ./mysql_install_db \
\> --basedir=/usr/local/mysql \
\> --datadir=/usr/local/mysql/data \
\> --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK
启动服务
[root@localhost ~]# service mysqld start
Starting MySQL... SUCCESS!
[root@localhost ~]# netstat -anutp | grep mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0: LISTEN 28170/mysqld
设置密码(这里使用自带的安全脚本)
[root@localhost ~]# mysql_secure_installation
……
Set root password? [Y/n]
New password: 1
Re-enter new password: 1
Password updated successfully!
……
查看授权表
[root@localhost ~]# mysql -uroot -p1
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| root | localhost |
+------+-----------+
3 rows in set (0.01 sec)
删除多余的授权数据项
mysql> delete from mysql.user where host='::1';
Query OK, 1 row 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> delete from mysql.user;
Query OK, 2 rows affected (0.00 sec)
mysql> grant all privileges on
.* to system@'localhost' identified by '123' with grant option;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
with grant option 此参数可以指定此用户可以授权别人权限
mysql> select user,host from mysql.user;
+--------+-----------+
| user | host |
+--------+-----------+
| system | localhost |
+--------+-----------+
1 row in set (0.00 sec)

觉得本文章不错的可以分享给您的朋友或订阅我,后期会分享更多的Linux技术文章