centos 6.2下 源码安装mysql 5.5.22

时间:2021-12-07 17:08:39

centos 6.2 源码安装mysql 5.5.22

 

1.  安装mysql 相关依赖库(没有的话就安装,有就不用安装了)  

通过 rpm -qa | grep name 的方式验证以下软件包是否已全部安装。
gcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel* libmcrypt*   libtool*

没有的话安装:

yum安装:

#yum install bison gcc gcc-c++ autoconf automake zlib* libxml* ncurses-devel  libtool

rpm –ivh 安装:

例如:rpm -ivh MySQL-devel-4.0.24-0.i386.rpm

2.安装cmake

# wgethttp://www.cmake.org/files/v2.8/cmake-2.8.6.tar.gz

# tar zxvf cmake-2.8.6.tar.gz

# cd cmake-2.8.6/

# ./configure

# gmake

# gmake install  

 

3.添加用户和创建数据库目录和权限设置

# group add mysql

#useradd mysql –g mysql

# mkdir -p /data/mysql

# chown -R mysql:mysql /data/mysql

 

4.MYSQL 5.5.22安装

#cd /usr/local/src

# wget http://down1.chinaunix.net/distfiles/mysql-5.5.22.tar.gz

# tar zxvf mysql-5.5.22.tar.gz

# cd mysql-5.5.22

# cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc-DMYSQL_DATADIR=/mysql/data -DMYSQL_TCP_PORT=3306-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_USER=mysql

# gmake

# gmake install

 

5.设置mysql配置文件

# cd /usr/local/mysql

# cp ./support-files/my-huge.cnf/etc/my.cnf 

 

5.1编辑/etc/my.cnf

# vi /etc/my.cnf

在 [mysqld] 段增加

datadir = /data/mysql

wait-timeout = 30

max_connections = 512

max_connect_errors = 10000000

default-storage-engine = MyISAM

 

在 [mysqld] 段修改

max_allowed_packet = 16M 

 

[mysqld_safe]增加字段

log-error=/data/mysql/log/mysqld.log

 

6.初始化数据库

#cd /usr/local/mysql

# 9 ./scripts/mysql_install_db --datadir=/data/mysql--basedir=/usr/local/mysql --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

# chkconfig --level 35 mysqld on

 

7.设置启动脚本变量 

  编辑 /etc/rc.d/init.d/mysqld

# vi /etc/rc.d/init.d/mysqld

basedir=/usr/local/mysql

datadir=/data/mysql 

 

8.设置变量环境

# echo"PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile(永久生效)

# export PATH=$PATH:/usr/local/mysql/bin(当前生效)

或者

# . /etc/profile

 

9.启动服务

# service mysqld start

 

10.设置数据库管理员root密码 重新启动mysqld服务

# mysqladmin -u root password '123456'

# service mysqld restart

 

 查看mysql服务:

[root@tata data]#netstat-npalt | grep 3306

tcp       0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      25051/mysqld  

查看mysql进程

[root@tata data]#ps -ef | grep "mysql"

root    24737     1  0 08:04 pts/1    00:00:00 /bin/sh/usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql--pid-file=/data/mysql/tata.domain.pid

mysql   25051 24737  0 08:04 pts/1    00:00:00 /usr/local/mysql/bin/mysqld--basedir=/usr/local/mysql --datadir=/data/mysql--plugin-dir=/usr/local/mysql/lib/plugin --user=mysql--log-error=/data/mysql/tata.domain.err --pid-file=/data/mysql/tata.domain.pid--socket=/tmp/mysqld.sock --port=3306

root    25130  2648  0 08:24 pts/1    00:00:00 mysql -u root -p

root    25183  9149  0 08:34 pts/2    00:00:00 grep mysql

11.进入Mysql 

# mysql -u root -p

输入密码

mysql> show databases;

+-----------------------+

| Database              |

+-----------------------+

| information_schema    |

| mysql                 |

| #mysql50#mysql-5.5.22 |

| performance_schema    |

| test                  |

+-----------------------+

5 rows in set (0.00 sec)

 

mysql> use mysql;

Database changed

mysql> show tables;

+---------------------------+

| Tables_in_mysql           |

+---------------------------+

| columns_priv              |

........


11.管理mysql ,建表,建库

 

显示mysql存储引擎

mysql>showengines;

 

编码方式更改
show variables like 'character_set_%';
setcharacter_set_client=utf8;