Linux编译MySQL

操作系统:CentOS release 5.4 (Final)

数据库:MySQL-5.5.20-1.linux2.6.x86_64.tar

系统环境:

gcc gcc-c++ autoconf automake zlib* libxml* ncurses-devel libmcrypt* libtool*(libtool-ltdl-devel*)

 

# yum –y install gcc gcc-c++ autoconf automake zlib* libxml* ncurses-devel libmcrypt* libtool*

 

建立MySQL安装目录及数据存放目录

[root@cncloud download]# mkdir /usr/local/mysql

[root@cncloud download]# mkdir /var/mysqldata

 

查看系统中现有的用户和用户组是否包含了mysql

[root@cncloud ~]# grep -in mysql /etc/passwd /etc/group

/etc/passwd:36:mysql:x:500:503::/data/mysqldata:/sbin/nologin

/etc/group:49:mysql:x:503:

 

如果没有找到,创建用户和用户组

groudadd mysql

useradd -g mysql mysql

 

赋予数据存放目录权限

chown mysql.mysql -R /var/mysqldata

 

安装cmakeMySQL 5.5以后是通过cmake来编译的

下载地址:http://www.cmake.org/files/v2.8/cmake-2.8.7.tar.gz

 

wget http://www.cmake.org/files/v2.8/cmake-2.8.7.tar.gz

./configure

gmake && make install

 

安装MySQL-5.5.20-1.linux2.6.x86_64.tar

wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.20.tar.gz

 

tar zxvf mysql-5.5.20.tar.gz

 

cd mysql-5.5.20

 

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_UNIX_ADDR=/var/mysqldata/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DMYSQL_DATADIR=/var/mysqldata \

-DMYSQL_USER=mysql \

-DMYSQL_TCP_PORT=3306

 

gmake

make install

 

安装成功后,进入安装目录:

cd /usr/local/mysql

复制配置文件:

[root@cncloud mysql]# cp support-files/my-medium.cnf /etc/my.cnf

 

初始化数据库

[root@cncloud mysql]# chmod 755 scripts/mysql_install_db

[root@cncloud mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/var/mysqldata/

Installing MySQL system tables...

OK

Filling help tables...

OK

 

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

 

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

 

/usr/local/mysql//bin/mysqladmin -u root password 'new-password'

/usr/local/mysql//bin/mysqladmin -u root -h cncloud.com.cn password 'new-passwor                                                                                        d'

 

Alternatively you can run:

/usr/local/mysql//bin/mysql_secure_installation

 

which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.

 

See the manual for more instructions.

 

You can start the MySQL daemon with:

cd /usr/local/mysql/ ; /usr/local/mysql//bin/mysqld_safe &

 

You can test the MySQL daemon with mysql-test-run.pl

cd /usr/local/mysql//mysql-test ; perl mysql-test-run.pl

 

Please report any problems with the /usr/local/mysql//scripts/mysqlbug script!

 

设置mysql开机启动:

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

 

[root@cncloud mysql]# chmod 755 /etc/init.d/mysql

[root@cncloud mysql]# chkconfig mysql on

 

启动mysql服务:

[root@cncloud mysql]# /etc/init.d/mysql start

Starting MySQL....

 

查看命令是否启动:

[root@cncloud mysql]# ps -ef | grep mysql

root      5234     1  0 13:52 pts/8    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/var/mysqldata --pid-file=/var/mysqldata/cncloud.com.cn.pid

mysql     5500  5234  0 13:53 pts/8    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/var/mysqldata --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/mysqldata/cncloud.com.cn.err --pid-file=/var/mysqldata/cncloud.com.cn.pid --socket=/var/mysqldata/mysql.sock --port=3306

root      6114 11649  0 13:54 pts/8    00:00:00 grep mysql

 

设置MySQL编码:(自己编译的加入以下红色字体配置会启动报错,可能是字符集冲突,使用默认的配置文件就可以了)

vim /etc/my.cnf

[client]

#password       = your_password

port            = 3306

socket          = /var/mysqldata/mysql.sock

default-character-set=utf8

# Here follows entries for some specific programs

 

# The MySQL server

[mysqld]

port            = 3306

socket          = /var/mysqldata/mysql.sock

skip-external-locking

key_buffer_size = 16M

max_allowed_packet = 1M

table_open_cache = 64

sort_buffer_size = 512K

net_buffer_length = 8K

read_buffer_size = 256K

read_rnd_buffer_size = 512K

myisam_sort_buffer_size = 8M

default-character-set=utf8

init-connect='SET NAMES utf8'

 

 

设置密码:

mysqladmin -u root password '123456'

 

mysql -uroot -p123456

你可能感兴趣的:(Linux MySQL 编译)