1.先查看系统上有没有安装了旧版本的MySQL,用下面的命令:
rpm -qa | grep mysql
如果有,用以下命令卸载
rpm -e --nodeps 上步显示mysql名称
安装编译mysql 需要的依赖包
yum install libevent* libtool* autoconf* libstd* ncurse* bison* openssl*
yum -y install gcc gcc-c++
2.安装cmake,mysql5.5之后需要用cmake支持编译安装,下载安装cmake
wget http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz
tar -xf cmake-2.8.12.1.tar.gz
cd cmake-2.8.12.1
./configure && make && make install
检查cmake安装好了没
cmake --version
3.下载mysql
wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.14.tar.gz
tar xvf mysql-5.6.14.tar.gz
cd mysql-5.6.14
上面如果下载失败,可以到这里下载:http://download.csdn.net/detail/terry_water/6973721
4.编译安装
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1-DWITH_INNOBASE_STORAGE_ENGINE=1-DWITH_MEMORY_STORAGE_ENGINE=1-DWITH_READLINE=1-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306-DENABLED_LOCAL_INFILE=1-DWITH_PARTITION_STORAGE_ENGINE=1-DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make && make install
如果在上面的编译报错,Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH),则使用下面的编辑代码:
cmake -DCURSES_LIBRARY=/usr/lib/libncurses.so -DCURSES_INCLUDE_PATH=/usr/include -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1-DWITH_INNOBASE_STORAGE_ENGINE=1-DWITH_MEMORY_STORAGE_ENGINE=1-DWITH_READLINE=1-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306-DENABLED_LOCAL_INFILE=1-DWITH_PARTITION_STORAGE_ENGINE=1-DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
要很长时间的等待,我虚拟机中安装是双核2G内存,花了20分钟左右的。
另外还可能遇到下面的错误:
1.
yum install libevent* libtool* autoconf* libstd* ncurse* bison* openssl*
报错:
libevent2-devel conflicts with libevent-devel-1.4.13-4.el6.x86_64
则执行:
yum install libevent2 libtool* autoconf* libstd* ncurse* bison* openssl*
2.
查看 ls /usr/lib/libncurses.so
如果找不到,则
find / -name ‘libncurses.so’
我找到的文件如下:
/usr/lib64/libncurses.so
增加快捷方式
ln -s /usr/lib64/libncurses.so /usr/lib/libncurses.so
5.配置mysql
groupadd mysql
useradd -g mysql mysql
chown -R mysql:mysql /usr/local/mysql
初始化配置
cd /usr/local/mysql
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
配置自启动和启动mysql
cp support-files/mysql.server /etc/init.d/mysql
chkconfig mysql on
service mysql start
配置PATH
vi /etc/profile
#在文件末尾添加
PATH=/usr/local/mysql/bin:$PATH
export PATH
#保存退出,生效配置
source /etc/profile
登陆mysql 并设置root密码
mysql -uroot
mysql> SET PASSWORD =PASSWORD('123456');
设置mysql可以远程访问
mysql> GRANT ALL PRIVILEGES ON *.* TO'root'@'%'IDENTIFIED BY'123456'WITH GRANT OPTION;
执行下边的命令,使上边的命令生效
flush privileges;
如果是远程,配置可以远程访问,配置防火墙,允许3306端口
/sbin/iptables -I INPUT -p tcp --dport3306-j ACCEPT
/etc/rc.d/init.d/iptables save
6.数据库定时备份:
mkdir /backup
chmod777-R /backup
vim /backup/mysql_backup.sh
写入如下内容:-p引号里面是数据库的密码,erp是备份的数据库名字
#!/bin/bash
date=$(date +%Y%m%d)
/usr/local/mysql/bin/mysqldump -h localhost -uroot -p'Ddsd#$#2s$!s4343%$^&s'erp > /backup/databases-$date.sql
设置CRON,定时备份:
crontab -e
0006* * * /bin/bash /backup/mysql_backup.sh
网友评论