yum remove mysql mysql-server mysql-libs mysql-server; find / -name mysql 將找到的相關東西delete掉(rm -rf /var/lib/mysql) rpm -qa|grep mysql(查詢出來的東東yum remove掉) rm /etc/my.cnf
查看是否還有mysql軟件:mysql
rpm -qa|grep mysql
若是存在的話,繼續刪除便可。sql
[root@localhost opt]# rpm -qa | grep -i mysql MySQL-server-5.6.17-1.el6.i686 MySQL-client-5.6.17-1.el6.i686
卸載mysql
[root@localhost local]# rpm -e MySQL-server-5.6.17-1.el6.i686 [root@localhost local]# rpm -e MySQL-client-5.6.17-1.el6.i686
刪除mysql服務 [root@localhost local]# chkconfig --list | grep -i mysql [root@localhost local]# chkconfig --del mysql
刪除分散mysql文件夾 [root@localhost local]# whereis mysql 或者 find / -name mysql
mysql: /usr/lib/mysql /usr/share/mysql
清空相關mysql的全部目錄以及文件
rm -rf /usr/lib/mysql
rm -rf /usr/share/mysqlshell
rm -rf /usr/my.cnf數據庫
經過以上幾步,mysql應該已經徹底卸載乾淨了.服務器
在MySQL官網中下載YUM源rpm安裝包:http://dev.mysql.com/downloads/repo/yum/ 網絡
# 下載mysql源安裝包 wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安裝mysql源 yum localinstall mysql57-community-release-el7-8.noarch.rpm
shell> yum repolist enabled | grep "mysql.*-community.*"
yum install mysql-server
yum install mysql-devel
systemctl start mysqld //打開MySQL服務
systemctl status mysqld //能夠查看MySQL服務是否正常打開(可省略)
grep "temporary password" /var/log/mysqld.log
CentOS系統用yum安裝MySQL的朋友,請使用 grep "temporary password" /var/log/mysqld.log 命令,返回結果最後引號後面的字符串就是root的默認密碼。優化
如圖能夠看出,我此次安裝的MySQL的初始密碼是【S+NwpxfZt0o;】spa
#######安裝成功後,將其加入開機啓動
[root@typecodes ~]# systemctl enable mysqld
#######啓動mysql服務進程
[root@typecodes ~]# systemctl start mysqld
#######配置mysql(設置密碼等)
[root@typecodes ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation.
Set root password? [Y/n] y [設置root用戶密碼] New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y [刪除匿名用戶] ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y [禁止root遠程登陸] ... Success! By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y [刪除test數據庫] - Dropping test database... ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist ... Failed! Not critical, keep moving... - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y [刷新權限] ... Success! All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL! Cleaning up...
在原始配置文件 /etc/my.cnf 基礎上,在 [mysqld] 節內增長配置參數。實際應用中,請按硬件及負載酌情修改。.net
#add by feng 120418 -------------------------- #skip-locking skip-name-resolve skip-external-locking key_buffer_size = 256M #table_cache = 3072 table_open_cache = 3072 read_buffer_size = 2M read_rnd_buffer_size = 2M sort_buffer_size = 2M myisam_sort_buffer_size = 256M thread_cache_size = 8 query_cache_size= 512M query_cache_limit= 5M tmp_table_size=1024M max_heap_table_size=3000M max_allowed_packet = 16M innodb_buffer_pool_size = 512M innodb_log_file_size = 512M innodb_additional_mem_pool_size=512M innodb_log_buffer_size=64M max_connections=2000 max_user_connections=800 join_buffer_size = 8M open_files_limit = 65535 #tmpdir=/dev/shm max_connect_errors=1000 #add by feng 120418 end ---------------------
1:安裝完成路徑: 1、數據庫目錄 /var/lib/mysql/ 2、配置文件 /usr/share/mysql(mysql.server命令及配置文件) 3、啓動腳本 /etc/rc.d/init.d/(啓動腳本文件mysql的目錄) 4、相關命令 /usr/bin(mysqladmin mysqldump等命令) 注:1~3安裝server安裝後存在,4mysqladmin mysqldump在client安裝後存在 b、中止 service mysqld stop c、重啓 service mysqld restart y d, 啓動 service mysqld start e, 強行關閉MySQL killall mysqld f, 查看是否啓動成功,進程mysql啓動,網絡端口3306開啓爲ok. ps aux | grep mysql g, 登陸 mysql -u root -p f, 查看MySQL中all user SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user; h, 容許遠程機器用root用戶鏈接MySQL服務器數據庫 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION; FLUSH PRIVILEGES;
或 UPDATE USER SET HOST = '%' WHERE HOST='127.0.0.1' AND USER='root'