linux下编译安装mysql

Linux下编译安装MySQL


下面是在 CentOS 6.5 下编译安装 MySQL 5.6.20 。


1. 首先卸载系统自带的 mysql
# yum remove mysql 

2.安装cmake 

下载cmake源码
# wget http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz

# tar xzfv cmake-2.8.5.tar.gz
# cd cmake-2.8.5
# ./configure
( 如果提示没安装C++编译器就先安装C++编译器:# yum -y install gcc-c++ )
# make 
# make install

查看 cmake 版本
# cmake -version

3.安装 ncurses 和 bison
# yum -y install ncurses-devel
# yum -y install bison

4. 创建mysql组和用户
# groupadd mysql
# useradd -g mysql mysql 

5. 创建数据库目录及分配访问权限
# mkdir -p /u01/app/mysql
# chown -R root:mysql /u01/app/mysql
# chown -R mysql:mysql /u01/app/mysql/data

6. 编译安装mysql
下载mysql源码
# wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.20.tar.gz

# tar xzfv mysql-5.6.20.tar.gz
# cd mysql-5.6.20
# cmake . -DCMAKE_INSTALL_PREFIX=/u01/app/mysql -DMYSQL_DATADIR=/u01/app/mysql/data -DSYSCONFDIR=/etc

参数说明:
-DCMAKE_INSTALL_PREFIX    //安装根目录
-DINSTALL_DATADIR         //数据存储目录
-DSYSCONFDIR              //配置文件(my.cnf)目录

# make 
# make install

7. 配置 mysql
# cd /u01/app/mysql
# cp ./support-files/my-default.cnf /etc/my.cnf 

# vi /etc/my.cnf
在 [mysqld] 段修改
basedir = /u01/app/mysql
datadir = /u01/app/mysql/data

保存退出编辑。

8. 初始化数据库
# cd /u01/app/mysql
# ./scripts/mysql_install_db  --defaults-file=/etc/my.cnf --user=mysql
# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld

9. 设置变量环境
# echo "PATH=$PATH:/u01/app/mysql/bin" >> /etc/profile (永久生效)
# export PATH=$PATH:/u01/app/mysql/bin (当前生效)

10. 启动服务
# service mysqld start
/etc/init.d/mysqld: line 46: /u01/app/mysql: is a directory
/etc/init.d/mysqld: line 47: /u01/app/mysql/data: is a directory
Starting MySQL.                                            [  OK  ]

11. 设置数据库管理员root密码
# mysqladmin -u root password '123456'
(注:在当前会话窗口操作,否则会出现 “mysqladmin: command not found” 错误,除非重新启动系统。)

重新启动服务
# service mysqld restart 
/etc/init.d/mysqld: line 46: /u01/app/mysql: is a directory
/etc/init.d/mysqld: line 47: /u01/app/mysql/data: is a directory
/etc/init.d/mysqld: line 46: /u01/app/mysql: is a directory
/etc/init.d/mysqld: line 47: /u01/app/mysql/data: is a directory
Shutting down MySQL.                                       [  OK  ]
/etc/init.d/mysqld: line 46: /u01/app/mysql: is a directory
/etc/init.d/mysqld: line 47: /u01/app/mysql/data: is a directory
Starting MySQL.                                            [  OK  ]

12. 进入 MySQL
# mysql -u root -p
(注:在当前会话窗口操作,否则会出现 “mysql: command not found” 错误,除非重新启动系统。)
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.20 Source distribution

Copyright (c) 2000, 2014, 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> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select Host,User,Password from user; 
+-----------------------+------+-------------------------------------------+
| Host                  | User | Password                                  |
+-----------------------+------+-------------------------------------------+
| localhost             | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost.localdomain | root |                                           |
| 127.0.0.1             | root |                                           |
| ::1                   | root |                                           |
| localhost             |      |                                           |
| localhost.localdomain |      |                                           |
+-----------------------+------+-------------------------------------------+
6 rows in set (0.00 sec)

mysql> 
展开阅读全文

没有更多推荐了,返回首页