一 更換yum
1備份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2更新阿里yum源 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
3 查看cd /etc/yum.repos.d/
4 yum clean all
5 yum makecache
二 下載配置mysql的yum源的rpm包
wget https://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm
安裝用來配置mysql的yum源的rpm包
rpm -Uvh mysql57-community-release-el6-9.noarch.rpm
安裝成功後在/etc/yum.repos.d/下會多出幾個mysql的yum源的配置
[root@zat2 yum.repos.d]# ls
CentOS-Base.repo CentOS-fasttrack.repo mysql-community.repo
CentOS-Base.repo.backup CentOS-Media.repo mysql-community-source.repo
三 安裝mysql
[root@zat2 yum.repos.d]# rpm -qa | grep mysql
[root@zat2 yum.repos.d]# yum install mysql-community-server
四 開啓mysql
[root@zat2 yum.repos.d]# service mysqld restart
中止 mysqld: [肯定]
初始化 MySQL 數據庫: [失敗]
[root@zat2 yum.repos.d]# service mysqld restart
中止 mysqld: [肯定]
正在啓動 mysqld: [肯定]
[root@zat2 yum.repos.d]# ps -ef | grep mysqlmysql
密碼sql
[root@zat2 yum.repos.d]# grep 'temporary password' /var/log/mysqld.log
2018-07-19T20:33:49.986448Z 1 [Note] A temporary password is generated for root@localhost: efl!>rif<2xUshell
centos 6設置開機自啓數據庫
[root@zat2 yum.repos.d]# chkconfig --add mysqld
[root@zat2 yum.repos.d]# chkconfig mysqld on
[root@zat2 yum.repos.d]# chkconfig list
[root@zat2 yum.repos.d]# chkconfig --listcentos
五報錯處理
[root@zat2 ~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@zat2 ~]# vi /etc/my.cnf
在[mysqld]後面任意一行添加「skip-grant-tables」用來跳過密碼驗證的過程
[root@zat2 ~]# service mysqld restart
中止 mysqld: [肯定]
正在啓動 mysqld: [肯定]
[root@zat2 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.22 MySQL Community Server (GPL)安全
第二新安裝的MySQL5.7,登陸時提示密碼錯誤,安裝的時候並無更改密碼,後來經過免密碼登陸的方式更改密碼,輸入update mysql.user set password=password('root') where user='root'時提示ERROR 1054 (42S22): Unknown column 'password' in 'field list',原來是mysql數據庫下已經沒有password這個字段了,password字段改爲了socket
authentication_string
因此更改語句替換爲update mysql.user set authentication_string=password('root') where user='root' ;便可插件
mysql設置密碼
[root@zat2 yum.repos.d]# mysqladmin -uroot -p password 'zat'
Enter password:
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
mysqladmin:
You cannot use 'password' command as mysqld runs
with grant tables disabled (was started with --skip-grant-tables).
Use: "mysqladmin flush-privileges password '*'" instead
[root@zat2 yum.repos.d]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.22 MySQL Community Server (GPL)rest
centos 7 安裝mysql5.7日誌
卸載maridb
[root@zatt ~]# yum remove mariadb*
殺死yum進程
kill -9 `ps -ef |grep yum |awk '{print $2}' `
1配置YUM源
# 下載mysql源安裝包
shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安裝mysql源
shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm
檢查mysql源是否安裝成功
[root@zatt ~]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 51
mysql-tools-community/x86_64 MySQL Tools Community 63
mysql57-community/x86_64 MySQL 5.7 Community Server 267
二、安 裝MySQL
shell> yum install mysql-community-server
三、啓動MySQL服務
shell> systemctl start mysqld
查看MySQL的啓動狀態
shell> systemctl status mysqld
四、開機啓動
shell> systemctl enable mysqld
shell> systemctl daemon-reload
五、修改root本地登陸密碼
mysql安裝完成以後,在/var/log/mysqld.log文件中給root生成了一個默認密碼。經過下面的方式找到root默認密碼,而後登陸mysql進行修改:
[root@zatt ~]# grep 'temporary password' /var/log/mysqld.log
2018-07-18T13:24:49.210585Z 1 [Note] A temporary password is generated for root@localhost: Mq:kNQP(4?Zh
shell> mysql -u root -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
或者
mysql> set password for 'root'@'localhost'=password('MyNewPass4!');
注意:mysql5.7默認安裝了密碼安全檢查插件(validate_password),默認密碼檢查策略要求密碼必須包含:大小寫字母、數字和特殊符號,而且長度不能少於8位。不然會提示ERROR 1819 (HY000): Your password does not satisfy the current policy
修改密碼策略
在/etc/my.cnf文件添加validate_password_policy配置,指定密碼策略
# 選擇0(LOW),1(MEDIUM),2(STRONG)其中一種,選擇2須要提供密碼字典文件
validate_password_policy=0
若是不須要密碼策略,添加my.cnf文件中添加以下配置禁用便可:
validate_password = off
從新啓動mysql服務使配置生效:
systemctl restart mysqld
默認配置文件路徑:
配置文件:/etc/my.cnf
日誌文件:/var/log//var/log/mysqld.log
服務啓動腳本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid
若是忘記root密碼,則按以下操做恢復:
在[mysqld]的段中加上一句:skip-grant-tables 保存而且退出vi。
mysql -u root
update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';
flush privileges