Linux系統下卸載mysql 停止mysql服務 systemctl stop mysqld.service 查看安裝的mysql服務 rpm -qa|grep -i mysql 刪除安裝的mysql服務 rpm -e --nodeps mysql相關服務 #例如: rpm -e --nodeps ...
Linux系統下卸載mysql
-
停止mysql服務
systemctl stop mysqld.service
-
查看安裝的mysql服務
rpm -qa|grep -i mysql
-
刪除安裝的mysql服務
rpm -e --nodeps mysql相關服務 #例如: rpm -e --nodeps mysql-community-client-5.7.26-1.el7.x86_64 rpm -e --nodeps mysql-community-common-5.7.26-1.el7.x86_64 rpm -e --nodeps mysql-community-libs-5.7.26-1.el7.x86_64 rpm -e --nodeps mysql-community-server-5.7.26-1.el7.x86_64
-
刪除遺留信息和文件
-
查詢殘留的文件和相關依賴
find / -name mysql
-
移除殘留的的文件和相關依賴
rm -rf 文件目錄 #例如: rm -rf /var/lib/mysql rm -rf /var/lib64/mysql rm -rf /usr/share/mysql rm -rf /usr/local/mysql
-
-
刪除mysql配置文件
rm -rf /etc/my.cnf
-
檢查mysql是否成功刪除
rpm -qa|grep -i mysql
Linux系統【tar包】方式安裝mysql5.7
-
創建mysql目錄
mkdir /usr/local/mysql
-
切換到mysql目錄
cd /usr/local/mysql
-
上傳tar包到mysql目錄
-
**查詢並卸載 Mariadb **
#查詢 Mariadb rpm -qa|grep mariadb #卸載 Mariadb rpm -e --nodeps mariadb服務名 #例如: rpm -e --nodeps mariadb-libs
-
解壓tar包
tar -xvf mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar
-
安裝所需服務
rpm -ivh mysql服務名 #例如: rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm
-
運行mysql服務
systemctl start mysqld.service
-
設置root用戶密碼
#Mysql自動給root用戶設置隨機密碼,運行如下命令可獲取初始密碼 grep "password" /var/log/mysqld.log
-
登陸進入mysql命令行
mysql -u root -p
-
設置密碼策略並修改密碼
set global validate_password_policy=LOW; #設置密碼安全策略 set global validate_password_length=4; #設置密碼長度 set password for 'root'@'localhost' =password('root');#設置密碼
-
刷新MySQL的系統許可權相關表,使得密碼生效
flush privileges;
-
環境變數
#將MYSQL的BIN⽬錄加⼊PATH環境變數,⽅便以後在任意⽬錄上都可以使⽤ mysql 提供的命令。 vim ~/.bash_profile #在⽂件末尾處追加如下信息: export PATH=$PATH:/usr/local/mysql/bin #最後執⾏如下命令使環境變數⽣效: source ~/.bash_profile
-
設置遠程主機登錄
#關閉Linux防火牆 systemctl stop firewalld #授權登錄方式 set global validate_password_policy=LOW; #設置密碼安全策略 set global validate_password_length=4; #設置密碼長度 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY "root"; flush privileges; #官方推薦的兩種方式: You can run the following command in your MySQL server command prompt. Please consult with your database administrator as they usually will have administration right to set the privilege. GRANT ALL PRIVILEGES ON *.* TO 'YourUserName'@'%' IDENTIFIED BY "YourPassword"; or GRANT ALL PRIVILEGES ON *.* TO 'YourUserName'@'YourIP' IDENTIFIED BY "YourPassword";
-
常用命令
#啟動mysql服務: systemctl start mysqld.service #狀態查看: systemctl status mysqld #設置開機自啟: systemctl enable mysqld #重啟mysql: systemctl restart mysqld