CentOS卸载编译安装MYSQL

作者: gaohailin 分类: 网站技术 发布时间: 2011-09-14 16:08

第一步:清理工作首先删除系统中原有的mysql,如果以前安装过的话可用yum list mysql*查看系统中是否安装过mysql,如果有,则用yum remove package_name删除;
然后删除mysql用户userdel -r mysql
最后删除系统中残留的与mysql相关的文档: rm -rvf find \ -name *mysql*


第二步:安装相关工具
yum installgcc gcc-c++ 


cmake(mysql 5.5.x 不再用 configure,而用cmake)

cd $HOME/src  #(源码存放目录,之前已建好)

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

 tar xvf  cmake-2.8.4.tar.gz

 cd cmake-2.8.4

 ./configure

sudo make

sudo make install


第三步:下载编译安装mysql

 

cd $HOME/src

#两个任选一个

wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.15.tar.gz/from/ftp://ftp.cs.pu.edu.tw/Unix/mysql/

 

http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.15.tar.gz/from/ftp://ftp.stu.edu.tw/pub/Unix/Database/Mysql/

 

 tar zxvf mysql-5.5.15.tar.gz

 cd mysql-5.5.15

#关于下面的参数在前面一篇已经说过 

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_DATADIR=/data/mysql/data \

         -DWITH_MYISAM_STORAGE_ENGINE=1 \

         -DWITH_INNOBASE_STORAGE_ENGINE=1 \

         -DWITH_ARCHIVE_STORAGE_ENGINE=1 \

         -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

         -DENABLED_LOCAL_INFILE=1 \

         -DDEFAULT_CHARSET=utf8 \

         -DDEFAULT_COLLATION=utf8_general_ci \

         -DEXTRA_CHARSETS=all \

         -DMYSQL_TCP_PORT=3306

        

sudo make

sudo make test

sudo make install

 

mysql 配置

 userdel -r mysql

 sudo groupadd -g 3306 mysql

 sudo useradd -u 3306 -g mysql -M -s /sbin/nologin mysql

 sudo  mkdir -p /data/mysql/data

 sudo mkdir -p /data/mysql/log

 sudo chown -R mysql:mysql /data/mysql

 sudo chmod -R 755 /data/mysql

 sudo cp support-files/my-medium.cnf /etc/my.cnf

 sudo /usr/local/mysql/scripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/data/mysql/data &   //初始化数据库

 sudo cp support-files/mysql.server /etc/init.d/mysqld

 chmod +x /etc/init.d/mysqld

 sudo /sbin/chkconfig –add mysqld

 sudo /sbin/chkconfig mysqld on

 sudo /sbin/service  mysqld start

 netstat -tnlp |grep 3306

 

cd /usr/local/bin //进入用户的默认搜索路径下建立mysql命令的软连接,可以直接执行mysql命令

 sudo ln -s /usr/local/mysql/bin/mysql mysql

 sudo ln -s /usr/local/mysql/bin/mysqldump mysqldump

 sudo ln -s /usr/local/mysql/bin/mysqladmin  mysqladmin

 

 mysqladmin -u root -p password ‘your_password’  //设置数据库密码

 mysql -u root -p

 mysql> flush privileges;


#到这里安装基本结束了,各位可根据自己的情况再做进一步的优化

#下面是安装使用过程中出现的一些问题及解决方法

 

一.不能用root用户运程连接mysql

*******************************************************************************

为MySQL的root用户添加远程访问权限:

[root@localhost ~]# mysql -uroot -p
Enter password: (此处输入密码登录)
Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 35 to server version: 5.0.22

Type ‘help;’ or ‘/h’ for help. Type ‘/c’ to clear the buffer.

 

 

mysql> grant all on *.* to root@’%’ identified by ‘your_password’;
Query OK, 0 rows affected (0.01 sec)

 

mysql> exit
Bye

 

[root@localhost ~]# /etc/init.d/mysqld restart

*******************************************************************************

 

二.Mysqld启动失败

*******************************************************************************

1)  mysql相关进程僵死

查找mysql相关进程:sudo ps –A | grep mysql

杀死相关进程:sudo kill -9 process_id

重启mysqld:sudo /etc/init.d/mysqld restart

 

 

2)优化后出现

Starting MySQL..The server quit without updating PID file ([失败]ocal/mysql/data/localhost.localdomain.pid).

这个问题主要出现的原因是因为my.cnf的配置过于高,当前的机器无法满足,导致了MYSQL启动失败,估计以后也会有很多人遇到这个问题,网上的标准是:

 

如果内存是128M,则复制/usr/local/share/mysql/my-medium.cnf为/etc/my.cnf

# This is for a system with little memory (32M – 64M) where MySQL plays

# an important part, or systems up to 128M where MySQL is used together with

# other programs (such as a web server)

 

如果内存是512M,则复制/usr/local/share/mysql/my-large.cnf为/etc/my.cnf

# This is for a large system with memory = 512M where the system runs mainly

# MySQL.

 

如果内存是1-2G,则复制/usr/local/share/mysql/my-huge.cnf为/etc/my.cnf

# This is for a large system with memory of 1G-2G where the system runs mainly

# MySQL.

实际上需要在my-medium.cnf的基础上进行修改,增强部分配置,不能直接使用my-large.cnf和my-huge.cnf。

除非你的服务器配置相当高。

 

3)./mysql-bin.index not found

权限问题修改数据目录的权限及/usr/local/mysql/bin/mysqld 的权限。

 

4)Error Code : 1418
This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
(0 ms taken)

解决方法如下:

1. mysql> SET GLOBAL log_bin_trust_function_creators = 1;

2. 在my.ini(linux下为my.conf)文件中 [mysqld] 标记后加一行内容为 log-bin-trust-function-creators=1

如果觉得我的文章对您有用,请随意赞赏。您的支持将鼓励我继续创作!

发表评论

邮箱地址不会被公开。 必填项已用*标注