1. 程式人生 > >阿里雲 centos 安裝mysql+基本配置

阿里雲 centos 安裝mysql+基本配置

檢視當前linux環境,確定使用哪個版本的mysql

# rpm -q centos-release

centos-release-7-4.1708.el7.centos.x86_64

新增 Mysql 源頭

cd /etc/yum.repos.d/

vim mysql.repo


# Enable to use MySQL 8.0

[mysql80-community]

name=MySQL 8.0 Community Server

baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/

enabled=1

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

驗證 Mysql 源頭

# yum repolist enabled | grep mysql

mysql80-community MySQL 8.0 Community Server

使用yum 安裝 mysql

# yum install -y mysql-community-common mysql-community-libs mysql-community-client mysql-community-server mysql-community-devel


==========================================================================================

 Package 架構 版本 源 大小

==========================================================================================

正在安裝:

 mysql-community-client x86_64 8.0.12-1.el7 mysql80-community 26 M

 mysql-community-common x86_64 8.0.12-1.el7 mysql80-community 541 k

 mysql-community-devel x86_64 8.0.12-1.el7 mysql80-community 4.0 M

 mysql-community-libs x86_64 8.0.12-1.el7 mysql80-community 2.2 M

      替換 mariadb-libs.x86_64 1:5.5.56-2.el7

 mysql-community-libs-compat x86_64 8.0.12-1.el7 mysql80-community 2.1 M

      替換 mariadb-libs.x86_64 1:5.5.56-2.el7

 mysql-community-server x86_64 8.0.12-1.el7 mysql80-community 349 M

為依賴而安裝:

 libaio x86_64 0.3.109-13.el7 base 24 k



事務概要

==========================================================================================

安裝 6 軟體包 (+1 依賴軟體包)

配置

包含資料初始化配置和基本建庫步驟

啟動Mysql服務

# service mysqld start

檢視MySQL伺服器的狀態

# service mysqld status

設定開機啟動

# chkconfig mysqld on

生成隨機密碼

# grep ‘temporary password’ /var/log/mysqld.log

2018-10-16T06:02:34.500574Z 5 [Note] [MY-010454] [Server] A temporary password is generated for [email protected]: nMXRrVN55

重新登入

# mysql -uroot -p nMXRrVN55

選配 如果嫌棄密碼驗證太麻煩,可以調低策略

mysql8 中使用 set global validate_password.policy=0;

mysql5.7 中使用 set global validate_password_policy=0;

配置Mysql 密碼及其許可權

# ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘xxxxxx’;

檢視使用者

SELECT DISTINCT CONCAT(‘User: ‘’’,user,’’’@’’’,host,’’’;’) AS query FROM mysql.user;

建立使用者

CREATE USER ‘code’@’%’ IDENTIFIED BY ‘xxxxxx’;

建立資料庫

create database box_office default character set utf8mb4 collate utf8mb4_unicode_ci;

檢視資料庫

show databases;

授權

GRANT ALL ON box_office.* TO ‘code’@’%’;

檢視授權

show grants for [email protected]’%’;

更改使用者密碼

SET PASSWORD FOR ‘code’@’%’ = PASSWORD(“xxxxxx”);

取消授權

REVOKE privilege ON box_office.*FROM ‘code’@‘host’;

刪除使用者

DROP USER ‘code’@‘host’;

caching_sha2_password

Mac 版本的 Sequel Pro 1.1.2 看來還不支援 Mysql8 的登陸,會遇到這個錯誤,是由於 mysql8 預設使用了「caching_sha2_password」這個更高階的密碼加密方式。

MySQL said: Authentication plugin ‘caching_sha2_password’ cannot be loaded: dlopen(/usr/local/lib/plugin/caching_sha2_password.so, 2): image not found

需要使用者的密碼加密方式,從「caching_sha2_password」改成「mysql_native_password」

使用以下命令使使用者密碼加密方式立即生效

ALTER USER ‘username’@‘ip_address’ IDENTIFIED WITH mysql_native_password BY ‘password’;

修改配置檔案如下,vim /etc/my.cnf 儲存後重啟mysql

[mysqld] default_authentication_plugin=mysql_native_password

不過我即使把這個問題解決了,還是用不上 Mysql8 ,開啟會 Sequel Pro 會報錯。

刪除Mysql

查詢mysql安裝情況

rpm -qa|grep -i mysql


[[email protected] ~]# rpm -qa|grep -i mysql

mysql-community-libs-8.0.12-1.el7.x86_64

mysql-community-devel-8.0.12-1.el7.x86_64

mysql-community-common-8.0.12-1.el7.x86_64

mysql-community-server-8.0.12-1.el7.x86_64

mysql-community-client-8.0.12-1.el7.x86_64

mysql-community-libs-compat-8.0.12-1.el7.x86_64

停止mysql服務,刪除上面的列表包名
# service mysqld stop

# rpm -ev mysql-community-libs-8.0.12-1.el7.x86_64 --nodeps

# rpm -ev mysql-community-devel-8.0.12-1.el7.x86_64 --nodeps

# rpm -ev mysql-community-common-8.0.12-1.el7.x86_64 --nodeps

# rpm -ev mysql-community-server-8.0.12-1.el7.x86_64 --nodeps

# rpm -ev mysql-community-client-8.0.12-1.el7.x86_64 --nodeps

# rpm -ev mysql-community-libs-compat-8.0.12-1.el7.x86_64 --nodeps

查詢mysql檔案和庫,並刪除


[[email protected] ~]# find / -name mysql
/var/lib/mysql
/var/lib/mysql/mysql
/etc/selinux/targeted/active/modules/100/mysql



[[email protected] ~]# rm -rf /var/lib/mysql

[[email protected] ~]# rm -rf /var/lib/mysql/mysql

[[email protected] ~]# rm -rf /etc/selinux/targeted/active/modules/100/mysql

刪除my.cnf

rm -rf /etc/my.cnf