Centos上安装MySQL

1、去官网查找最新(你需要的)安装包版本
# https://dev.mysql.com/downloads/repo/yum/

2、下载MySQL安装包

# wget http://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

3、安装MySQ源

# yum -y install mysql80-community-release-el7-3.noarch.rpm

4、查看安装结果

# yum repolist enabled | grep mysql.*
mysql-connectors-community/x86_64       MySQL Connectors Community           128
mysql-tools-community/x86_64            MySQL Tools Community                100
mysql80-community/x86_64                MySQL 8.0 Community Server           145

5、安装MySQL服务

# yum install mysql-community-server -y

6、启动MySQL

# service mysqld start
# netstat -lntp | grep 3306            //查看3306端口是否起了
# systemctl status mysqld.service      //查看MySQL的运行状态

7、查看MySQL日志,筛选出临时密码

# grep "password" /var/log/mysqld.log

8、用临时密码登录到MySQL

# mysql -uroot -p

9、更改root密码,密码要大小写加字符(密码有复杂性要求)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpasswd'

10、修改 /etc/my.cnf 或 /etc/mysql/my.cnf,文件加入 utf-8编码

# vim /etc/my.cnf                  //把下面代码粘进去就好
[client]
default-character-set = utf8
[mysqld]
default-storage-engine = INNODB
character-set-server = utf8
collation-server = utf8_general_ci
 
# service mysqld restart          //重启数据库即可
 

 

posted @ 2019-10-15 10:51  Brother_Cat  阅读(228)  评论(0编辑  收藏  举报