centos 安装mysql
1.安装从网上下载文件的wget命令
[root@master ~]# yum -y install wget
2.下载mysql的repo源
[root@master ~]# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
3.安装mysql-community-release-el7-5.noarch.rpm包
[root@master ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
4.安装mysql
[root@master ~]# yum install mysql-server
5.安装mysql 服务器端
yum install mysql-server
yum install mysql-devel
6.设置mysql 的配置文件
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
character_set_server=utf8
lower_case_table_names=1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
7.启动mysql 服务。
启动
service mysqld start
重启
service mysqld restart
关闭
service mysqld stop
8.设置密码
service mysqld start
mysqladmin -u root password 123456
9.error: ‘Access denied for user ‘root’@‘localhost’ (using password: NO)’ 解决方案
10.查看数据库
show databases;
11.设置开机启动
systemctl enable mysqld.service
12.停止mysql服务开机自启动
systemctl disable mysqld.service
13.查看mysql服务当前状态
systemctl status mysqld.service
14.关闭centos 的防火墙,出现10060 错误的解决办法。
#安装 Firewalld
yum install firewalld
#安装界面
yum install firewall-config
# 启动
# systemctl start firewalld
# 开机启动
# systemctl enable firewalld
# 关闭
# systemctl stop firewalld
# 取消开机启动
# systemctl disable firewalld
# 重启防火墙
firewall-cmd --reload
# 查看状态
systemctl status firewalld或者 firewall-cmd --state
15。如果出现MySQL 1130错误,无法远程连接
mysql -u root -p
mysql>use mysql;
mysql>select 'host' from user where user='root';
mysql>update user set host = '%' where user ='root';
mysql>flush privileges;
mysql>select 'host' from user where user='root';
16.如果出现ERROR 1062 (23000): Duplicate entry ‘%-root’ for key ‘PRIMARY’
select host from user where user = 'root';
+-----------------------+------+
| host | user |
+-----------------------+------+
| % | root |
| 127.0.0.1 | root |
| ::1 | root |
| localhost.localdomain | root |
如果host已经有了%这个值,所以直接运行命令:
MySQL>flush privileges;