CentOS6.x下源码安装MySQL5.5
1. 更新yum源:http://www.cnblogs.com/vurtne-lu/p/7405931.html
2. 卸载原有的mysql数据库
[root@zabbix ~]# yum -y remove mysql mysql-server mysql-libs compat-mysql51 [root@zabbix ~]# rm -rf /var/lib/mysql [root@zabbix ~]# rm /etc/my.cnf [root@zabbix ~]# rpm -qa|grep mysql #如果还能查询出来mysql文件,继续删除,没有的话就说明mysql已经彻底删除了
3. 安装依赖包
yum -y install cmake gcc* ncurses-devel mysql-devel net-snmp-devel
4. 添加mysql用户和用户组,创建mysql的数据目录
[root@zabbix ~]# groupadd mysql [root@zabbix ~]# mkdir -pv /data/mysql [root@zabbix ~]# useradd -r -g mysql -d /data/mysql -s /sbin/nologin mysql [root@zabbix ~]# chown -R mysql.mysql /data/mysql
5. 安装MySQL
[root@zabbix opt]# wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49.tar.gz [root@zabbix opt]# tar -zxvf mysql-5.5.49.tar.gz [root@zabbix opt]# cd mysql-5.5.49 [root@zabbix mysql-5.5.49]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/product/mysql-5.5.49 -DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DDEFAULT_COLLATION=utf8_general_ci [root@zabbix mysql-5.5.49]# make && make install [root@zabbix mysql-5.5.49]# ln -s /usr/local/product/mysql-5.5.49 /usr/local/mysql #添加软链接 [root@zabbix mysql-5.5.49]# chown -R mysql.mysql /usr/local/mysql #给软链接添加所属用户和组 [root@zabbix mysql-5.5.49]# cd /usr/local/mysql/support-files/ [root@zabbix support-files]# cp my-medium.cnf /data/mysql/my.cnf #拷贝mysql配置文件
6. 将mysql添加service管理
[root@zabbix support-files]# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld [root@zabbix support-files]# chmod +x /etc/rc.d/init.d/mysqld
7. 初始化数据库
[root@zabbix support-files]# cd /usr/local/mysql/scripts [root@zabbix scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/
8. 修改MySQL配置文件my.cnf中的数据目录
[root@zabbix scripts]# vim /etc/my.cnf datadir=/data/mysql/ #在[mysqld]下修改
9. 启动mysql
[root@zabbix ~]# /etc/init.d/mysqld start Starting MySQL... SUCCESS! 或者 [root@zabbix ~]# service mysqld start Starting MySQL... SUCCESS!
10. 查看mysql版本
[root@yeebian scripts]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.49-log Source distribution 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>
注:如果在执行mysql命令时出现以下错误:
[root@zabbix ~]# mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
解决方法:
[root@zabbix ~]# ln -s /tmp/mysql.sock /var/lib/mysql/
11. 建库、添加权限及用户密码
mysql> UPDATE mysql.user SET Password=PASSWORD('zabbix') where USER='root'; #添加root用户密码 mysql> create database zabbix default charset utf8; #创建zabbix数据库并赋予utf8字符集; mysql> grant all privileges on zabbix.* to zabbix@'localhost' identified by 'zabbix'; #将数据库zabbix下的所有权限赋予用户zabbix,密码为zabbix mysql> flush privileges; #刷新MySQL的系统权限相关表 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | zabbix | +--------------------+ 5 rows in set (0.00 sec)