准备工作:
MYSQL的安装过程中需要从网上下载部分支持包
yum install glibc.i686
yum -y install libaio.so.1 libgcc_s.so.1 libstdc++.so.6
yum -y update libstdc+±4.4.7-4.el6.x86_64
yum install gcc-c++
yum -y install numactl
3.Linux系统上安装MySQL:
下载链接:https://dev.mysql.com/downloads/mysql/
Centos7:
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-1.el7.x86_64.rpm-bundle.tar
(1).执行命令查看Linux是否安装mysql:
rpm -qa | grep mysql
卸载系统原生jdk(想用自己版本的jdk)
rpm -e --nodeps mysql-libs-5.1.71-1.el6.i686
(2).用相关工具(winSCP等)上传安装文件到linux:
(3).依次安装MySQL
rpm -ivh mysql-community-common-5.7.22-1.el6.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.22-1.el6.x86_64.rpm
rpm -ivh mysql-community-client-5.7.22-1.el6.x86_64.rpm
rpm -ivh mysql-community-server-5.7.22-1.el6.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.22-1.el6.x86_64.rpm
(4).启动MySQL的服务
service mysqld start
(5).查看初始管理员密码
grep ‘temporary password’ /var/log/mysqld.log
你会发现初始管理员密码是很复杂:[Note] A temporary password is generated for root@localhost:xxxxxxxx
(6).停止mysqld服务,编辑配置文件/etc/my.cnf,添加配置项(有的版本配置文件:/etc/mysql/mysql.conf.d/mysqld.cnf) 跳过权限表的限制,免密登陆: skip-grant-tables
(7).启动mysqld服务,执行mysql
update mysql.user set authentication_string=password(‘123456’) where User=‘root’ and Host=‘localhost’;
flush privileges;
如果报错: Your password does not satisfy the current policy requirements 需要设置复杂密码。
如果是为了测试,就是想设置简单的密码!办法还是有的,修改当前策略:
修改策略:
设置密码 123456 发现还是失败,猜测是可能是length问题,查看:
(8).去掉配置文件中skip-grant-tables配置项,一定别忘记删除这个配置。
(9).设置开机自动启动mysql:
添加到系统服务:
chkconfig --add mysqld
自动启动:
chkconfig mysqld on
(10).开启远程登录,授权远程登录用户:
grant all privileges on *.* to ‘用户名’@’%’ identified by ‘密码’ with grant option;
flush privileges;
(11).设置防火墙(开放3306端口,linux默认拦截3306端口):
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
保存配置
/etc/rc.d/init.d/iptables save
如果感觉修改配置文件麻烦,也可以如下操作: 用(5)获取的原始配置密码登陆:
mysql -uroot -p 回车:原始密码
-->1: SET PASSWORD = PASSWORD('your new password');
--> 2: ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
--> 3: flush privileges;
这样相当于完成(6),(7),(8)步操作