Linux环境下服务器环境搭建-mysql

时间:2021-05-06 17:00:13

下载对应版本的mysql.rpm(Linux 6 安装el6 Linux 7 安装el7)

安装环境 centos 7,安装版本mysql57-community-release-el7-9.noarch(最新版本(自带安装源,注:目前Linux环境无最新mysql版本,大约为5.1))

1、卸载已安装版本

yum list installed | grep mysql

yum –y remove mysql*

rpm -qa|grep mysql

rpm -e --nodeps musql*

2.安装

2.1 下载含安装源的rpm文件

http://dev.mysql.com/downloads/repo/yum/

2.2 添加安装源

rpm -Uvh platform-and-version-specific-package-name.rpm

2.3 检查安装源是否添加成功

yum repolist all | grep mysql

可修改默认安装源(一般不用修改)vim /etc/yum.repos.d/mysql-community.repo

默认enable = 1;不默认为0

2.4 查看可用安装源

yum repolist enabled | grep mysql

2.5 安装Mysql

yum install mysql-community-server

2.6 开启/关闭服务

service mysqld start/stop

2.7 查看服务状态

service mysqld status

2.8 查看默认安装密码

grep 'temporary password' /var/log/mysqld.log (切记此密码,初始化密码)

2.9 默认密码登陆并修改密码 5.7强密码策略(大小写字母,特殊字符,数字,不少于8位)

mysql -uroot -p

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

3.0 开启远程登陆

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'MyNewPass4' WITH GRANT OPTION;

刷新权限

FLUSH PRIVILEGES

3.1 修改默认编码

vi /etc/my.cnf

[mysqld]

character_set_server=utf8

init_connect='SET NAMES utf8'