CentOS 5.6 X86_64
下载通用Linux二进制包
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz
可以用国内的镜像,比较快,如北理工
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz
用户mysql01的用户组为mysql
groupadd mysql
useradd -g mysql mysql01
将安装包复制到mysql01用户下
cp mysql-5.7.9.tar.gz ~mysql01/
修改权限
chown mysql01:mysql ~mysql01/mysql-5.7.9.tar.gz
切换用户
su - mysql01
解压
tar -xf mysql-5.7.9.tar.gz
重命名目录为mysql
mv mysql-5.7.9 mysql
su - mysql01
vim .bash_profile
添加
export MYSQL_HOME=/home/mysql01/mysql/
export PATH=$PATH:$MYSQL_HOME/bin
重新加载下
source .bash_profile
设置MYSQL_HOME是为了找到该目录下的my.cnf配置文件
设置PATH环境变量是为了直接运行mysql,mysqladmin等程序
检查是否已安装mysql-server,mysql客户端等,如果有,请卸载
rpm -qa|grep mysql
检查是否有全局mysql配置文件/etc/my.cnf,如果有,请删除。
su - mysql01
cd mysql
vim my.cnf设置如下内容
[mysqld]
basedir=/home/mysql01/mysql/
datadir=/home/mysql01/mysql/data
port=13306
#defalut /tmp/mysql.sock
socket=/tmp/mysql01.sock
user=mysql01
character-set-server=utf8
#default 151
max_connections=500
#default 2000, please set this value max_connections * N
table_open_cache=4000
#innodb buffer pool大小 1073741824为1G
innodb_buffer_pool_size=1073741824
#date flush
innodb_max_dirty_pages_pct=75
#ssd please increment innodb_io_capacity
innodb_io_capacity=200
innodb_io_capacity_max=2000
#ssd disable neighbors flush,set to 0, 1 is flush same extends contiguous dirty pages,2 is flush same extends dirty pages
innodb_flush_neighbors=1
#log file defalut 50M
#104857600表示100M ssd please increment this value
innodb_log_file_size=104857600
innodb_log_files_in_group=2
#flush_log 1,2,0
innodb_flush_log_at_trx_commit=1
#default in data directory hostname.err
#log-error=/home/mysql01/mysql/data/mysql01.err
[mysqld_safe]
#used by msyqld_sale,default in data directory hostname.pid
#pid-file=/home/mysql01/mysql/data/mysql.pid
[mysql]
socket=/tmp/mysql01.sock
port=13306
[mysqladmin]
socket=/tmp/mysql01.sock
port=13306
[mysqldump]
socket=/tmp/mysql01.sock
port=13306
[mysql.server]
basedir=/home/mysql01/mysql/
su - mysql01
cd mysql
mkdir data
bin/mysqld --initialize --user=mysql01
如果不报建错,注意最后一行出现的随机密码,后面再修改
2015-12-29T21:57:46.756551Z 1 [Note] A temporary password is generated for root@localhost: v8U%cgyn5QRB
su - mysql01
cd mysql
bin/mysqld_safe &
启动过程中如果有错误,请参见MYSQL_HOME/data目录下的err日志文件,进行错误排除,一般都是配置参数错误,没有权限之类的问题,再不就是缺少依赖软件包,这些请自行解决。
su - mysql01
cd mysql
bin/mysql -uroot -p'v8U%cgyn5QRB'
alter user 'root'@'localhost' identified by 'root'
这里我们把密码改为root,生产环境可不能这么任性,设置如此简单的密码。这里仅作演示,安全意识很重要啊!各位切记。
如果忘记了初始密码,也可以使用skip-grant-tables方式重置密码。
su - mysql01
cd mysql
bin/mysqld_safe --skip-grant-tables
bin/mysql -uroot
update user set authentication_string = password('root'), password_expired = 'N', password_last_changed = now() where user = 'root';
su - mysql01
cd mysql
bin/mysql -uroot -p
输入密码进入系统,创建一个测试数据库testdb
create database testdb;
创建用户test,可以从本机和192.168.31.0网段登录,密码为testpwd
GRANT ALL PRIVILEGES ON testdb.* TO 'test'@'localhost' IDENTIFIED BY 'testpwd' ;
GRANT ALL PRIVILEGES ON testdb.* TO 'test'@'192.168.31.%' IDENTIFIED BY 'testpwd' ;
刷新权限
FLUSH PRIVILEGES;
登录测试
mysql -u test -p
输入密码testpwd登录
use testdb;
create table t1 (id int,name varchar(20));
insert into t1 values (1,"zhangsan");
insert into t1 values (1,"李四");
select * from t1;
测试完成,删除数据库testdb
mysql -uroot -p
drop table testdb;
修改/etc/sysconfig/iptables,添加
-A INPUT -m state --state NEW -m tcp -p tcp -s 192.168.31.0/24 --dport 13306 -j ACCEPT
重启
service iptables restart