欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Centos上安装MySQL

程序员文章站 2022-07-04 23:44:08
1、去官网查找最新(你需要的)安装包版本 # https://dev.mysql.com/downloads/repo/yum/ 2、下载MySQL安装包 # wget http://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.r ......
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          //重启数据库即可