mysql5.7.31二进制安装_centos7
#下载mysql5.7.31 community
https://downloads.mysql.com/archives/community
rpm -qa|grep mariadb
#卸载mariadb,文件名为上述命令查询出来的文件,/etc/my.cnf级联删除
rpm -e --nodeps 文件名
groupadd mysql
useradd -g mysql mysql
cd /usr/local
#将下载的压缩包放到/usr/local/
tar -zxvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.31-linux-glibc2.12-x86_64 mysql
mkdir /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql
vim /etc/my.cnf
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysqld]
server-id =1
log-bin=/usr/local/mysql/data/binlog/mysql-bin
max_binlog_size = 1G
binlog_format = row
binlog_row_image = full
#skip-name-resolve
#设置3306端口
port = 3306
socket=/var/lib/mysql/mysql.sock
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
#lower_case_table_name=1
max_allowed_packet=16M
[mysqld_safe]
log-error=/usr/local/mysql/data/mysqld.log
pid-file=/usr/local/mysql/data/mysqld.pid
#进入安装mysql软件目录
cd /usr/local/mysql
chown -R mysql:mysql ./
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
#注:若执行以上最后一个命令出现以下问题:
FATAL ERROR: please install the following Perl modules before executing
./scripts/mysql_install_db:Data::Dumper
解决方法 :安装autoconf库
命令: yum -y install autoconf //此包安装时会安装Data:Dumper模块
#配置开机启动
#授予my.cnf最大权限
chmod 644 /etc/my.cnf
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
#启动mysqld,跳过权限免密码登陆
service mysqld start --skip-grant-tables
#将mysql的bin目录加入PATH环境变量
vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile
#以root账户登录mysql,默认是没有密码的,要输入密码的时候直接回车即可。
mysql -uroot -p
#以skip-grant-tables启动,需要先flush privileges
flush privileges;
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('oracle');
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'oracle' WITH GRANT OPTION;
flush privileges;
service mysqld restart
mysql -uroot -poracle
#查询root@'localhost'和root@'%'用户权限
show grants for root@'localhost';
show grants for root@'%';
#若需要删除your root用户的权限
delete from user where user='your root';
flush privileges;
show variables like '%autocommit%';
#默认值innodb_flush_log_at_trx_commit和sync_binlog都是1
show variables like 'innodb_flush_log_at_trx_commit';
show variables like 'sync_binlog%';
#默认REPEATABLE-READ
show variables like '%transaction_isolation%';
mkdir -p /usr/local/mysql/data
chown mysql:mysql /usr/local/mysql/data/binlog
-----------------------------------
#创建应用用户
GRANT insert,update,delete,select ON *.* TO 'test'@'%' IDENTIFIED BY 'oracle' WITH GRANT OPTION;
flush privileges;
create database test default character set utf8mb4;
use test;
create table test.t1(id integer primary key auto_increment,name varchar(200));
insert into test.t1 select 1,'n1';
insert into test.t1 select 2,'n2';
create table test.t2(id integer primary key auto_increment,name varchar(200));
insert into test.t2 select 1,'n1';
select * from test.t1;
select * from test.t2;
-----------------------------------
#mysql5.7对group by语法更严格了,只能select 分组的字段和聚合函数,其他字段不允许出现在select列中,如果不想线上报错需要写此语句
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#参数设置前后对sql无影响
select count(*) from test.t1 GROUP by name;
select name,count(*) from test.t1 GROUP by name;
select name,count(id) from test.t1 group by name;
select @@sql_mode;
-----------------------------------
#配置防火墙
#firewall-cmd方式(CentOS7)
#permanent永久生效,没有此参数重启后失效
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --list-ports|grep 3306
#iptables方式(CentOS6)
vi /etc/sysconfig/iptables
-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
service iptables restart
Linux下开启/关闭防火墙命令
#1) 永久性生效,重启后不会复原
chkconfig iptables on
chkconfig iptables off
#2) 即时生效,重启后复原
service iptables start
service iptables stop