MySQL 5.7 安装(centos)

centos 6.9

# wget https://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm 
# rpm -Uvh mysql57-community-release-el6-9.noarch.rpm

centos7

# wget https://dev.mysql.com/get/ mysql57-community-release-el7-9.noarch.rpm
# rpm -Uvh mysql57-community-release-el7-9.noarch.rpm
# yum install mysql-community-server -y
# service mysqld start
mysql安装成功后创建的超级用户'root'@'localhost'的密码会被存储在/var/log/mysqld.log,可以使用如下命令查看密码
# grep 'temporary password' /var/log/mysqld.log
# mysql -uroot -p
输入密码
修改密码
mysql>set global validate_password_policy=0; #修改密码认证等级
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'jorudan0407';
mysql>use mysql;
mysql>update user set host ='%' where user ='root';
mysql>flush privileges;
mysql>quit;

端口

centos7
# firewall-cmd --add-port=3306/tcp --permanent
# firewall-cmd --query-port=3306/tcp   是否开启成功

centos6
# /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
# /etc/init.d/iptables save
# service iptables restart
# netstat -ntlp

问题一:

可能会报错:Requires: libc.so.6(GLIBC_2.17)
# cd /etc/yum.repos.d/
# sudo vi mysql-community.repo
找到mysql-56-community
将enable置为0 enable=0

问题二

登录时有可能报这样的错:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2),
原因是/var/lib/mysql的访问权限问题。下面的命令把/var/lib/mysql的拥有者改为当前用户:
# sudo chown -R root:root /var/lib/mysql
# use mysql;
# update user set password=password('123456') where user='root';

允许远程访问:

# mysql -u root -p;
mysql > GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql > FLUSH PRIVILEGES;

/var/log/mysqld.log 中找不到临时密码

1.删除原来安装过的mysql残留的数据(这一步非常重要,问题就出在这)
rm -rf /var/lib/mysql
2.重启mysqld服务
systemctl restart mysqld
3.再去找临时密码
grep 'temporary password' /var/log/mysqld.log

设置数据库不区分大小写

$ vim /etc/my.cnf
在 [mysqld] 的下一行添加内容   
lower_case_table_names=1

几种启动方式

1.service mysqld start
2./usr/local/mysql/support-files/mysql.server start    

-bash: mysql: command not found

# cd /usr/local/bin
# ln -fs /MYSQLPATH/bin/mysql mysql

你可能感兴趣的:(MySQL 5.7 安装(centos))