MySQL源码在linux下安装

参考以下:

http://www.jz123.cn/text/2937389.html

http://www.linuxidc.com/Linux/2011-01/31340p2.htm

http://zhouxuguang.blog.51cto.com/1053090/236292

1、安装cmake编译器

   这里下载了cmake-2.8.3.tar.gz
[root@localhost ~]# ls cmake-2.8.3.tar.gz
cmake-2.8.3.tar.gz
[root@localhost ~]# tar -zxvf cmake-2.8.3.tar.gz
[root@localhost ~]# cd cmake-2.8.3
[root@localhost cmake-2.8.3]# make && make install

 

2、添加必要的组和拥有者
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql mysql

3、编译安装MySql

这里下载了mysql-5.5.8.tar.gz

[root@localhost ~]# ls mysql-5.5.8.tar.gz
mysql-5.5.8.tar.gz
[root@localhost ~]# tar -zxvf mysql-5.5.8.tar.gz
[root@localhost ~]# mkdir -p /usr/local/mysql/data
[root@localhost ~]# cd mysql-5.5.8
[root@localhost mysql-5.5.8]# cmake  . \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DINSTALL_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.8]# make && make install

4、设置相关目录权限
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# chown -R mysql:mysql .
[root@localhost mysql]# chown -R mysql:mysql data

5、创建系统数据的表
[root@localhost mysql]# ./scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ --user=mysql

6、配置文件
[root@localhost mysql]# cp support-files/my-medium.cnf /etc/my.cnf

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

[root@localhost mysql]# vim /etc/rc.d/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
[root@localhost mysql]# chmod 755 /etc/rc.d/init.d/mysqld

7、设置环境变量
[root@localhost ~]# vim /root/.bash_profile
将PATH=$PATH:$HOME/bin修改为:
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
[root@localhost ~]# source /root/.bash_profile

8、启动MySql

手动启动MySql
[root@localhost ~]# mysqld_safe --user=mysql &  // 后台启动MySQL
[1] 25340
[root@localhost ~]# 130425 09:23:06 mysqld_safe Logging to

'/usr/local/mysql/data/localhost.localdomain.err'.
130425 09:23:06 mysqld_safe Starting mysqld daemon with databases from

/usr/local/mysql/data
[root@localhost ~]#
[root@localhost ~]# mysqladmin ping
mysqld is alive  // 说明成功启动了MySQL

// 注意MySQL里也有一个root用户,默认密码为空。MySQL的root用户跟Linux的root没有关系的。

// 故输入下面命令时,Enter passwd:直接回车就行了,因为MySQL的root用户密码默认为空。
[root@localhost ~]# mysqladmin -u root -p shutdown  // 停止MySQL服务
Enter password:
130425 09:25:01 mysqld_safe mysqld from pid file

/usr/local/mysql/data/localhost.localdomain.pid ended
[1]+  Done                    mysqld_safe --user=mysql
[root@localhost ~]#

设置引导时启动MySql:
[root@localhost ~]# cd /etc/rc.d/init.d/
[root@localhost init.d]# chkconfig --add mysqld
[root@localhost init.d]# chkconfig --level 345 mysqld on
[root@localhost init.d]#

[root@localhost ~]# ls -l /etc/rc.d/init.d/mysqld
-rwxr-xr-x 1 root root 10612 2013-04-25 09:16 /etc/rc.d/init.d/mysqld
[root@localhost ~]# chown mysql:mysql /etc/rc.d/init.d/mysqld
[root@localhost ~]# mysql  // 注意这里没有出现错误的原因是没有启动MySQL
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[root@localhost ~]# service mysqld start
Starting MySQL.                                            [  OK  ]
[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.8-log Source distribution

Copyright (c) 2000, 2010, 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.01 sec)

mysql>

你可能感兴趣的:(linux)