寫在前面 Clickhouse 從 21.11 版本開始,除了提供類似SqlServer、MySQL CREATE FUNCTION 的自定義函數之外,還有一個用戶自定義函數(UDF),與其說是“用戶自定義函數”,為了避免混淆,稱之為”用戶自定義外部函數“更為準確。官方對此功能的解釋: ClickH ...
一、清理環境
查看是否已安裝
#rpm -qa |grep -i mysql
#rpm -qa |grep -i mariadb --(centos7預設系統自帶的查看版本號併進行刪除)
#rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --刪除mariadb
# yum remove mariadb-libs-5.5.56-2.el7.x86_64 -- 刪除mariadb
# yum install perl perl-devel //安裝依賴包,根據各系統環境而定
二、開始安裝
#--上傳mysql rpm安裝包到伺服器(安裝包可以去oracle官網下載)
# rpm -ivh mysql-commercial-common-5.7.28-1.1.el7.x86_64.rpm
# rpm -ivh mysql-commercial-libs-5.7.28-1.1.el7.x86_64.rpm
# rpm -ivh mysql-commercial-libs-compat-5.7.28-1.1.el7.x86_64.rpm
# rpm -ivh mysql-commercial-client-5.7.28-1.1.el7.x86_64.rpm
# rpm -ivh mysql-commercial-server-5.7.28-1.1.el7.x86_64.rpm
-----or--下載安裝MySQL5.7社區版-----------------
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-common-5.7.28-1.el7.x86_64.rpm wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-libs-5.7.28-1.el7.x86_64.rpm wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-client-5.7.28-1.el7.x86_64.rpm wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
---------------------------------------------------------------
三、啟動&開機自啟
# systemctl enable mysqld
# systemctl start mysqld
# systemctl status mysqld
四、獲取隨機root密碼
# grep password /var/log/mysqld.log //日誌文件查找臨時密碼
# mysql -u root -p
Enter password:
五、修改密碼
修改當前登錄用戶
ALTER USER USER() IDENTIFIED BY 'Abc123@#$';
六、用戶管理
創建新用戶
mysql> use mysql;
mysql> create user 'admin'@'%' identified by 'Abc123@#$';
Query OK, 0 rows affected (0.00 sec)
授權
grant select ,insert,update on db1.t1 to "admin"@'%' identified by "Abc123@#$";
grant all privileges on db1.* to "admin"@'%' identified by "Abc123@#$";
grant all privileges on *.* to "admin"@'%' identified by "Abc123@#$";
取消授權
revoke all on db1.t1 from 'admin'@"%";
revoke all on db1.* from 'admin'@"%";
revoke all privileges on *.* from 'admin'@'%';
3)設置用戶 root 可以在任意 IP 下被訪問
grant all privileges on *.* to root@"%" identified by "Abc123@#$";
七、my.cnf參數配置調整MySQL數據存儲目錄datadir、socket
# systemctl stop mysqld
# cp -rp /var/lib/mysql /data --複製數據文件到新的目錄
# chown -R mysql:mysql /data/mysql
# vi /etc/my.cnf
-----my.cnf修改------
[client]
port=3306
#socket=/var/lib/mysql/mysql.sock
socket=/data/mysql/mysql.sock #修改socket目錄
[mysqld]
port=3306
#datadir=/var/lib/mysql
datadir=/data/mysql #修改數據文件目錄
#socket=/var/lib/mysql/mysql.sock
socket=/data/mysql/mysql.sock #修改socket目錄
------end------
[root@Centos7 tools]# systemctl start mysqld
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
[root@Centos7 tools]# /usr/bin/mysql start
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/data/mysql/mysql.sock' (2)
調整目錄後,MySQL無法啟動了,目錄許可權處理過,還是啟動不了
方法一、
臨時關閉SELinux:
# setenforce 0
永久關閉SELinux:
# vi /etc/sysconfig/selinux
然後將配置SELinux=enforcing改為SELinux=disabled
# sestatus ##查看SELinux狀態
# systemctl start mysqld --關閉SELinux後MySQL可以正常啟動
######datadir、socket路徑修改後因為SELinux安全問題導致無法啟動,在網上找了幾天也沒有人有說清楚,說到需關閉SELinux就已經不錯了。
其實真正的問題就是datadir、socket、log修改後的新路徑文件夾許可權只有MySQL用戶和用戶組,沒有其他的用戶,所以受SELinux影響無法寫入導致啟動失敗。
方法二、
# ls -ldZ /data/mysql ##查看目錄的SElinux 標簽
# yum provides semanage ###安裝
# yum -y install policycoreutils-python.x86_64 ###安裝
# chcon -Rv -u system_u -t mysqld_db_t /data/mysql
# semanage fcontext -a -t mysqld_db_t "/data/mysql(/.*)?"
# restorecon -Rv /data/mysql
# ls -ldZ /data/mysql ##再查看目錄的SElinux 標簽
# systemctl start mysqld ##處理後,MySQL啟動正常
八、防火牆埠開放
# firewall-cmd --zone=public --add-port=3306/tcp --permanent
# firewall-cmd --reload
九、通過客戶端遠程連接測試。OK完成