centos7 mysql安装与用户设置

1、环境:Centos 7.0 64位
2、mysql版本:5.7
3、安装:https://dev.mysql.com/doc/refman/5.7/en/installing.html
3.1、创建mysql用户和组:https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html
3.2、忘记 linux下mysql5.7 root用户的密码:
service mysqld stop
修改/etc/my.inf 末尾添加 skip-grant-tables
service mysqld start
use mysql
update user set authentication_string=password('Kd8k&dfdl023') where user='root';
flush privileges;
将/etc/my.inf中的skip-grant-tables 删掉;
service mysqld restart
mysql -uroot -p
use mysql
set password=password('newpassword');
3.3、创建mysql用户
https://dev.mysql.com/doc/refman/5.7/en/adding-users.html
mysql> CREATE USER 'finley'@'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'trade'@'%' WITH GRANT OPTION;
3.5、查看mysql端口:
mysql> show variables like 'port';
3.4、打开防火墙配置文件:
关闭并禁止firewall开机启动:
停止
systemctl stop firewalld.service
禁止开机启动
systemctl disable firewalld.service
安装iptables防火墙
yum install iptables-services
编辑防火墙配置文件打开指定的端口号使用udp协议打开52100端口:
vi /etc/sysconfig/iptables
保存退出
:wq
最后重启防火墙使配置生效
systemctl restart iptables.service
设置防火墙开机启动
systemctl enable iptables.service
3.5、查询mysql配置文件
locate my.cnf
查看mysql默认读取的配置列表:
mysql --help|grep 'my.cnf'
查看3306端口信息:
netstat -apn|grep 3306
修改mysql设置中的bind-address选项:
bind-address = 0.0.0.0
修改mysql设置中的port选项:
port=3308
----->使用阿里云服务器,需额外配置阿里云安全规则,设置入场端口!!!!!(巨坑。。)
4、创建数据库和数据表们:见sql文件。
5、centos设置cmd为支持中文
echo $LANG
yum group list
yum install system-config-users
yum groupinstall chinese-support
5.1、linux设置mysql编码为utf-8
6、linux 命令执行.sql文件
登录mysql
执行 source sqlpath