Centos安装mysql步骤详解

1.获取mysql YUM源。进入mysql官网获取RPM包下载地址

https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

复制网址https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

2.下载mysql源安装包

[root@localhost~]#wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

-bash: wget:未找到命令

先安装wget

[root@localhost ~]# yum -y install wget

在下载mysql源安装包

[root@localhost~]#wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

3.安装mysql 源

[root@localhost ~]# yum -y localinstall mysql80-community-release-el7-3.noarch.rpm

4.安装mysql

[root@localhost ~]# yum -y install mysql-community-server (时间较长,耐心等待..)

5.启动Mysql服务

[root@localhost ~]# systemctl start mysqld

6.设置开机启动

[root@localhost ~]# systemctl enable mysqld

[root@localhost ~]# systemctl daemon-reload

7.修改mysql 密码

[root@localhost ~]# vi /var/log/mysqld.log有临时密码

[root@localhost ~]#  mysql -u root -p

Enter password:

输入临时密码进入mysql命令行;

mysql> ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘******’;

8.设置允许远程登录

Mysql默认不允许远程登录,我们需要设置下,并且防火墙开放3306端口;

mysql> GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘******’ WITH GRANT OPTION;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘identified by “******” with grant option’ at line 1

注意:新版的mysql版本已经将创建账户和赋予权限的方式分开了

解决办法:

创建账户: create user ‘用户名’@’访问主机’ identified by ‘密码’;

赋予权限:grant 权限列表 on 数据库 to ‘用户名’@’访问主机’ ;(修改权限时在后面加with grant option)

mysql> create user ‘root’@’%’ identified by ‘******‘;

Query OK, 0 rows affected (0.01 sec)

 

mysql> grant all privileges on . to ‘root’@’%’ with grant option;

Query OK, 0 rows affected (0.00 sec)

mysql> exit;

9.设置开放3306 端口

[root@localhost ~]# firewall-cmd –zone=public –add-port=3306/tcp –permanent

[root@localhost ~]# firewall-cmd –reload

10.配置默认编码为utf8

修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

[mysqld]

character_set_server=utf8

init_connect=’SET NAMES utf8′

编辑保存完重启mysql服务:[root@localhost ~]# systemctl restart mysqld

查看编码: mysql> show variables like ‘%character%’

11.测试

补充:

5.6版本rpm     http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-release-el7-5.noarch.rpm

5.6版本修改密码update user set password=password(“123456″) where user=”root”;

文章来源于互联网,如有雷同请联系站长删除:Centos安装mysql步骤详解

发表评论