第一步:清理工作
首先删除系统中原有的mysql,如果以前安装过的话可用yum list mysql*查看系统中是否安装过mysql,如果有,则用yum remove package_name删除;
然后删除mysql用户userdel -r mysql
最后删除系统中残留的与mysql相关的文档: rm -rvf `find \ -name *mysql*`
第二步:安装相关工具
yum install gcc gcc-c++ ncurses-devel bison
cmake(mysql 5.5.x 不再用 configure,而用cmake)
cd $HOME/src #(源码存放目录,之前已建好)
wget
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
root账户密码设置,其它账户类似:
三种方法
使用SET PASSWORD语句
[root@localhost ~]# mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'host_name' = PASSWORD('newpwd')
使用mysqladmin命令行程序
[root@localhost ~]# mysqladmin -u root password "newpwd"
[root@localhost ~]# mysqladmin -u root -h host_name password "newpwd"
使用UPDATE语句
[root@localhost ~]# mysql -u root
mysql> UPDATE mysql.user SET Password = PASSWORD('newpwd')
-> WHERE User = 'root';
最后:
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