系统环境
CentOS 6.6
准备工作
- 安装gcc
[root@localhost ~]# yum install -y gcc gcc-c++ make automake
查看是否安装
[root@localhost ~]# gcc -version
- 安装wget
[root@localhost ~]# yum install -y wget
查看是否安装
[root@localhost ~]# wget --version
- 安装cmake
[root@localhost ~]# wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz [root@localhost ~]# tar -zxvf cmake-2.8.10.2.tar.gz [root@localhost ~]# cd cmake-2.8.10.2 [root@localhost ~]# ./bootstrap [root@localhost ~]# gmake [root@localhost ~]# gmake install
查看是否安装
[root@localhost ~]# cmake -v
- 安装ncurses-libs包
[root@localhost ~]# yum install ncurses-libs
- 安装ncurses-devel包
[root@localhost ~]# yum install ncurses-devel
安装MySQL
- 创建mysql的安装目录及数据库存放目录
[root@localhost ~]# mkdir -p /usr/local/mysql [root@localhost ~]# mkdir -p /usr/local/mysql/data
-
创建mysql用户及用户组
[root@localhost ~]# groupadd mysql [root@localhost ~]# useradd -r -g mysql mysql
-
安装mysql
[root@localhost ~]# cd /usr/mysql [root@localhost mysql]# tar -zxvf mysql-5.5.10.tar.gz [root@localhost mysql]# cd mysql-5.5.10 [root@localhost mysql-5.5.10]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1 [root@localhost mysql-5.5.10]# make [root@localhost mysql-5.5.10]# make install
参数说明:
-
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录
-
-DINSTALL_DATADIR=/usr/local/mysql/data //数据库存放目录
-
-DDEFAULT_CHARSET=utf8 //使用utf8字符
-
-DDEFAULT_COLLATION=utf8_general_ci //校验字符
-
-DEXTRA_CHARSETS=all //安装所有扩展字符集
-
-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
配置
-
设置目录权限
[root@localhost mysql-5.5.10]# cd /usr/local/mysql [root@localhost mysql]# chown -R root:mysql . //把当前目录中所有文件的所有者所有者设为root,所属组为mysql [root@localhost mysql]# chown -R mysql:mysql data //chown -R root:mysql /usr/local/mysql
-
将mysql的启动服务添加到系统服务中
[root@localhost mysql]# cp support-files/my-default.cnf /etc/my.cnf //将mysql的启动服务添加到系统服务中
-
创建系统数据库的表
[root@localhost mysql]# scripts/mysql_install_db --user=mysql
-
设置环境变量
[root@localhost mysql]# vi /root/.bash_profile PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib //追加进文件 [root@localhost mysql]# source /root/.bash_profile
-
启动mysql
-
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql //将mysql的启动服务添加到系统服务中 [root@localhost mysql]# yum install mysql-server [root@localhost mysql]# service mysql start //启动 [root@localhost mysql]# service mysql stop //停止 [root@localhost mysql]# service mysql restart //重启
- 修改MySQL的root用户的密码以及打开远程连接
[root@localhost mysql]# mysql -u root mysql
mysql> use mysql; mysql> desc user; mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; #为root添加远程连接的能力。 mysql> update user set Password = password('root') where User='root'; mysql> select Host,User,Password from user where User='root'; mysql> flush privileges; mysql> exit
若还不能进行远程连接,则关闭防火墙[root@localhost mysql]# /etc/rc.d/init.d/iptables stop
如果不能远程连接,出现错误mysql error number 1130,则加入下面语句试试:mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '******' WITH GRANT OPTION;
如果没有问题,MySQL就安装成功了!