Centos下安装Mysql5.5.x
采用mysql源码编译方式,编译器使用Cmake。软件需要mysql-5.5.35.tar.gz和cmake-2.8.10.2.tar.gz
下载地址:http://pan.baidu.com/s/1bnaUcMj
下载上述两个tar包完成后首先要安装cmake工具
假如上述两个包均放在 /opt 目录下,则执行如下命令:
a.安装bsion、ncurses-devel 与 cmake编译工具
cd /opt
yum install bison
yum -y install ncurses-devel
删除CMakeCache.txt
find / -name CMakeCache.txt
找到后全部删除
tar -zxvf cmake-2.8.10.2.tar.gz
cd cmake-2.8.10.2
./configure
make
make install
将cmake命令添加到系统环境
ln -s /usr/local/bin/cmake /usr/bin
b.安装编译mysql所需要的依赖包
yum install -y gcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel* libgcrypt* libtool*
c.创建安装目录及数据存放目录与用户创建
mkdir/usr/local/mysql
mkdir/data/mysql
groupadd mysql
useradd -g mysql mysql
chown mysql:mysql -R /data/mysql
d.安装Mysql5.5
tar -zxvf mysql-5.5.35.tar.gz
cd mysql-5.5.35
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1-DMYSQL_DATADIR=/data/mysql/ -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306
参数说明:
-DCMAKE_INSTALL_PREFIX=/home/mysql/mysql //安装目录
-DINSTALL_DATADIR=/home/mysql/data //数据库存放目录
-DDEFAULT_CHARSET=utf8 //使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci //校验字符
-DEXTRA_CHARSETS=all //安装所有扩展字符集
-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
make
make install
d.配置并初始化数据库
cd /opt/mysql-5.5.38
cp support-files/my-medium.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"?y
cd/usr/local/mysql/
chmod 755 scripts/mysql_install_db
scripts/mysql_install_db--user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/ &
cp support-files/mysql.server /etc/init.d/mysqld
chmod+x /etc/init.d/mysqld
/etc/init.d/mysqldstart
/usr/local/mysql/bin/mysql -u root -p
Enter password: 默认密码为空
查看mysql进程(两个)
ps -ef | grep mysql
查看Mysql监听端口
netstat -tnl
e.将mysql命令配置到系统环境
vi /etc/profile
PATH=$PATH:/usr/local/mysql/bin:
:wq
source /etc/profile
f.修改mysql密码为 12345
/usr/local/mysql/bin/mysqladmin -u root -p password 12345
提示输入原密码,直接接回车即可(默认为空)
g.配置mysql允许远程登陆
vim /etc/my.cnf
注释这一行:bind-address=127.0.0.1 ==> #bind-address=127.0.0.1
保存退出。
mysql -uroot -p12345
为需要远程登录的用户赋予权限:
复制代码 代码如下:
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "12345";
mysql> flush privileges;
远程登录命令:
mysql -h 192.168.1.100 -uroot -p(-h后跟的是要登录主机的ip地址)