二进制包安装 MySQL 5.5


:Mr.zhou  阅读: 2,838 次

  源代码编译方式安装Nginx logo-mysql

  源代码编译方式安装PHP

  当前环境

[root@nginx ~]# uname -r&&ifconfig eth0|awk -F "[ :]+" 'NR==2{print $4}'&&nginx -V&&php-fpm -v
2.6.32-504.el6.x86_64
172.16.1.140
nginx version: nginx/1.8.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx-1.8.0 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module
PHP 5.6.11 (fpm-fcgi) (built: Jul 16 2015 23:17:10)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
[root@nginx ~]# 

  从官网下载 MySQL 5.5 的二进制包

[root@nginx ~]# cd /usr/local/src/
[root@nginx src]# wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.32-linux2.6-x86_64.tar.gz
[root@nginx src]# tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz

  将解压的的文件移动到/usr/local/mysql-5.5.32 做软链接

[root@nginx src]# ls
mysql-5.5.32-linux2.6-x86_64
mysql-5.5.32-linux2.6-x86_64.tar.gz
[root@nginx src]# mv mysql-5.5.32-linux2.6-x86_64 /usr/local/mysql-5.5.32
[root@nginx src]# ln -s /usr/local/mysql-5.5.32/ /usr/local/mysql
[root@nginx src]# 

  创建 mysql 用户 安装数据库

[root@nginx src]# useradd -s /sbin/nologin -M mysql
[root@nginx src]# chown -R mysql.mysql /usr/local/mysql
[root@nginx src]# cd /usr/local/mysql
[root@nginx mysql]# ./scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

  将 mysql 提供的配置文件复制到 /etc/下

[root@nginx mysql]# cp ./support-files/my-small.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y
[root@nginx mysql]# 

  若 MySQL 的安装目录不是/usr/local下的mysql,则需要修改启动脚本 ./support-files/mysql.server 、./bin/mysqld_safe 中 mysql 安装目录

[root@nginx mysql]# sed -i 's#/usr/local/mysql#MySQL安装路径#g' ./support-files/mysql.server
[root@nginx mysql]# sed -i 's#/usr/local/mysql#MySQL安装路径#g' ./bin/mysqld_safe

  修改启动脚本中的mysql目录 并复制到 /etc/init.d/

[root@nginx mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@nginx mysql]# 

  将 MySQL 安装目录下的bin加入到环境变量

[root@nginx mysql]# echo -e 'PATH=/usr/local/mysql/bin:$PATH\nexport PATH'>>/etc/profile
[root@nginx mysql]# tail -2 /etc/profile
PATH=/usr/local/mysql/bin:$PATH
export PATH
[root@nginx mysql]# source /etc/profile
[root@nginx mysql]# 

  启动 mysql :

[root@nginx mysql]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS! 
[root@nginx mysql]# /etc/init.d/mysqld status
 SUCCESS! MySQL running (14557)
[root@nginx mysql]# 

  为 MySQL 的 root 用户设置密码,登陆数据库,删除不必要的库和用户

[root@nginx mysql]# mysqladmin -uroot password
New password: 
Confirm new password: 
[root@nginx mysql]# 

[root@nginx mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.32 MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

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       |
|      | localhost |
| root | localhost |
|      | nginx     |
| root | nginx     |
+------+-----------+
6 rows in set (0.01 sec)

mysql> drop user 'root'@'::1';drop user ''@'localhost';drop user ''@'nginx';drop user 'root'@'nginx';
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

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> 

转载请注明原文链接:http://www.z-dig.com/binary-packages-to-install-mysql-5-5.html



正文部分到此结束