liunx环境下安装mysql5.7及以上版本

 

1.系统环境

#cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core) 
#getenforce
Disabled
#systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
    Docs: man:firewalld(1)

2.配置yum源

#cd /etc/yum.repos.d
#vi mysql5.7.repo
[mysql5.7-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0 
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


##注意: 不用校验时mysql下载安装速度快,即将1更改为0! 我的系统是linux7,所以相应的baseurl中的地址要更改为linux7, 即http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/。如果系统是linux6,请为http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/ #清理缓存存储库 yum clean all #创建缓存存储库 yum makecache

3.查看是否有mysql安装包

yum repolist enabled | grep mysql

4.mysql的安装使用

#yum install mysql-community-server -y

#systemctl start mysqld.service

#mysql -V

//5.7以上版本的MySQL没有root的空密码
可以在配置文件中修改设置使用简单密码,/etc/my.cnf
validate_password_policy=0  //只匹配长度,默认8位
validate_password_length=4  //最小长度4位

#查看系统默认的root密码
grep 'temporary password' /var/log/mysqld.log
2019-06-23T11:13:14.861450Z 1 [Note] A temporary password is generated for root@localhost: qa!>h#BOu6eJ
##密码即:qa!>h#BOu6eJ
#使用root账户登入并修改root密码
mysql -uroot -p
mysql>set global validate_password_policy=0; //设置密码设置匹配最小长度默认8位

mysql>set global validate_password_length=1; //修改密码的长度
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '12345678';
##需要注意的是:
MySQL的 validate_password 插件默认安装。这将要求密码包含至少一个大写字母,一个小写字母,一个数字和一个特殊字符,并且密码总长度至少为8个字符。
mysql>show variables like 'validate_password%';

 

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

yum install libaio -y

mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql-5.7

groupadd mysql
useradd -r -g mysql mysql
mkdir -p /usr/local/mysql/mysql-5.7/data
chmod -R 755 /usr/local/mysql

./bin/mysqld  --initialize  --user=mysql  --basedir=/usr/local/mysql/mysql-5.7 --datadir=/usr/local/mysql/mysql-5.7/data

my.cnf
{
[mysqld]
basedir=/usr/local/mysql/mysql-5.7
datadir=/usr/local/mysql/mysql-5.7/data
socket=/var/lib/mysql/mysql.sock
port=3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=600
innodb_file_per_table=1
lower_case_table_names=1
character_set_server=utf8

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
socket=/var/lib/mysql/mysql.sock

[mysql]
socket=/var/lib/mysql/mysql.sock
!includedir /etc/my.cnf.d
}
mkdir -p /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown mysql:mysql /var/log/mariadb/mariadb.log
chmod 755 /var/log/mariadb/mariadb.log
mkdir -p /var/lib/mysql
chown mysql:mysql /var/lib/mysql
chmod 755 /var/lib/mysql
/usr/local/mysql/mysql-5.7/support-files/mysql.server start

 

#编辑环境变量
vim /etc/profile

#在文件最后面加入下面配置
export MYSQL_HOME=/usr/local/mysql/mysql-5.7.24
export MYSQL_PATH=${MYSQL_HOME}/bin:${MYSQL_HOME}/lib
export PATH=$PATH:/usr/local/mysql/mysql-5.7.24/bin

#保存后刷新环境变量
source /etc/profile

posted @ 2019-06-23 13:30  邓聪聪  阅读(592)  评论(0编辑  收藏  举报