wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
wget http://clientdown.xbsafe.cn/download/mysql/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
1、前期准备
安装依赖包:
yum install -y gcc gcc-c++ makezlib zlib-devel pcre* libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers bison
增加用户,创建要用的目录:
groupadd mysql
useradd -r -g mysql mysql
mkdir -p /disk/mysql/src/
chmod +w /disk/mysql/src/
chown -R mysql:mysql /disk/mysql/src
mkdir -p /etc/mysql
mkdir -p /disk/mysql
mkdir -p /disk/mysql/data/
mkdir -p /disk/mysql/log/
mkdir -p /disk/mysql/binlog/
mkdir -p /disk/mysql/relaylog/
mkdir -p /disk/mysql/tmp
mkdir -p /disk/mysql/redologs
chown -R mysql:mysql /disk/mysql/
环境变量:
export PATH="$PATH:/disk/redis/bin"
export PATH="$PATH:/disk/mysql/src/bin"
export PATH="$PATH:/disk/mysql3306/src/bin"
export PATH="$PATH:/disk/mysql3307/src/bin"
2、解压mysql
tar zxf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
#将目录直接copy到/usr/local目录下
mv mysql-5.6.26-linux-glibc2.5-x86_64 /disk/mysql/src/mysql
3、配置
在源码目录下support-files目录里有很多配置文件的模版
#拷贝主配置文件
vim /etc/my.cnf
#初始化mysql
cd /disk/mysql/src/mysql
./scripts/mysql_install_db --defaults-file=/etc/my.cnf
#创建启动脚本,cp后可以使用/etc/init.d/mysqld start启动
cp /disk/mysql/src/mysql/support-files/mysql.server /etc/init.d/mysqld
#修改权限
chmod 755 /etc/init.d/mysqld
多实例启动:
1) /disk/mysql/src/bin/mysqld --defaults-file=/etc/my.cnf &
2) /disk/mysql/src/bin/mysqld_safe --defaults-file=/etc/my.cnf &
/disk/mysql3306/src/mysql/bin/mysqld --defaults-file=/etc/mysql/my3306.cnf &
/disk/mysql3307/src/mysql/bin/mysqld --defaults-file=/etc/mysql/my3307.cnf &
初始登录方法:
1)mysql -h 127.0.0.1 -uroot -P 3307
2)mysqladmin -S /tmp/mysql3307.sock
多实例关闭:
1) /disk/mysql/src/bin/mysqladmin -S /tmp/mysql.sock shutdown ---推荐
1) /disk/mysql/src/bin/mysqladmin -h 127.0.0.1 -uroot -P 3306 -p
#修改权限
chmod 755 /etc/init.d/mysqld3307
#如果是rhel或者centos系统的话自启动文件/etc/rc.local
vim /etc/rc.local
/etc/init.d/mysqld3307 start
4、启动mysql
/etc/init.d/mysqld start
进入mysql,以下语句设置root密码删除没用的用户
/disk/mysql/src/bin/mysqladmin -u root password $mysqlrootpwd
use mysql;
update user set password=password(‘newpassword‘) where user=‘root‘;
delete from user where not (user=‘root‘) ;
delete from user where user=‘root‘ and password=‘‘;
drop database test;
DROP USER ‘‘@‘%‘;
flush privileges;
#mysql的一些安全设置
mysql_secure_installation
#mysql错误文件的位置
/usr/local/webserver/mysql/data/localhost.err
启动时的两个问题:
l启动报错:File‘./mysql-bin.index‘ not found (Errcode: 13)
解决办法:
一般就是权限问题,mysql用户是否对数据库目录内的所有文件具有写的权限
chown mysql.mysql -R data
l启动报错:0911029:10:22 [ERROR] Can‘t open the mysql.plugin table. Please run mysql_upgrade tocreate it.
解决办法:
出现这种问题是因为没有指定mysql安装目录和data目录导致的,运行如下命令:
# /usr/local/mysql/scripts/mysql_install_db --user=mysql--basedir=/usr/local/mysql --datadir=/usr/local/mysql/data