二进制包下载地址:https://yunpan.cn/cYzvuZvw9XeNI 访问密码 99a2
1.当前系统
[root@zexi ]# cat /etc/redhat-release
CentOS release 6.7 (Final)
2.下载mysql二进制包
[root@zexi ]#cd /usr/local/src
[root@zexi src]# wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.32-linux2.6-x86_64.tar.gz
[root@zexi src]tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz
3.将解压的文件移动到/usr/local/mysql-5.5.32做软链接
[root@zexi src]# mv mysql-5.5.32-linux2.6-x86_64 /usr/local/mysql-5.5.32
======/usr/local/mysql-5.5.32======就是安装目录
[root@zexi src]#ln -s /usr/local/mysql-5.5.32/ /usr/local/mysql
4.创建mysql用户安装数据库
[root@zexi src]#useradd -s /sbin/nologin -M mysql
[root@zexi src]#chown -R mysql.mysql /usr/local/mysql
[root@zexi src]#cd /usr/local/mysql-5.5.32
[root@zexi mysql-5.5.32]# ./scripts/mysql_install_db –basedir=/usr/local/mysql/mysql-5.5.32/ –user=mysql –datadir=/usr/local/mysql/data
5.将mysql提供的配置文件复制到/etc/下
[root@zexi mysql-5.5.32]# cp ./support-files/my-small.cnf /etc/my.cnf
6.若mysql的安装目录不是/usr/local下的mysql,则需要修改启动脚本 ./support-files/mysql.server和./bin/mysqld_safe中mysql安装目录
[root@zexi mysql-5.5.32]# sed -i ‘s#/usr/local/mysql#/usr/local/mysql-5.5.32#g’ ./support-files/mysql.server
[root@zexi mysql-5.5.32]# sed -i ‘s#/usr/local/mysql#/usr/local/mysql-5.5.32#g’ ./bin/mysqld_safe
7.修改启动脚本中的mysql目录并复制到/etc/init.d
[root@zexi mysql-5.5.32]# cp ./support-files/mysql.server /etc/init.d/mysqld
8.将mysql安装目录下的bin加入到环境变量
[root@zexi mysql-5.5.32]# echo -e ‘PATH=/usr/local/mysql-5.5.32/bin:$PATH\nexport PATH’>>/etc/profile
[root@zexi mysql-5.5.32]# tail -2 /etc/profile
[root@zexi mysql-5.5.32]# source /etc/profile
9.启动mysql
[root@zexi data]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
[root@zexi data]# /etc/init.d/mysqld status
SUCCESS! MySQL running (3063)
10.为mysql的root用户设置密码,登录数据库,删除不必要的库和用户
[root@zexi data]# mysqladmin -u root password
New password:
Confirm new password:
[root@zexi data]# mysql -u root -p
Enter password:
mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| performance_schema |
| test |
+——————–+
4 rows in set (0.01 sec)
mysql> drop database test;
mysql> select user,host from mysql.user;
+——+———–+
| user | host |
+——+———–+
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | zexi |
| root | zexi |
+——+———–+
mysql> drop user ‘root’@’::1’;
mysql> drop user ”@’localhost’;
mysql> drop user ”@’zexi’;
mysql> drop user ‘root’@’zexi’;
mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| performance_schema |
+——————–+
3 rows in set (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)
中间遇到的问题及解决办法见下一篇