因爲CentOS7自帶的是 Mariadb, 因此先來刪除他吧...html
1. 查找版本node
# rpm -qa|grep mariadb
執行命令後會出現相似 MariaDB-server-5.5.49-1.el7.centos.x86_64 之類的鬼..記住名字就好了.mysql
2. 刪除linux
# rpm -e --nodeps 上面查出來的文件名
3. 刪除配置文件sql
# rm /etc/my.cnf
在官方直接找吧 MySQL Community Server 5.5.62數據庫
選擇 Linux - Generic 注意bootstrap
推送到虛擬機或者遠程服務器, ftp 或者 rz, 或者直接圖形界面拖動隨你, 總之推上去就好了centos
解壓中注意若是出現EOF 報錯之類的須要考慮是否壓縮包文件損壞安全
嘗試更換壓縮包或者從新推送壓縮包bash
tar -xvf mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.5.62-linux-glibc2.12-x86_64 /usr/local
cd /usr/local mv mysql-5.5.62-linux-glibc2.12-x86_64 mysql-5.5.62
vi /etc/my.cnf
[mysql] # 設置mysql客戶端默認字符集 default-character-set=utf8 socket=/var/lib/mysql/mysql.sock [mysqld] skip-name-resolve #設置3306端口 port = 3306 socket=/var/lib/mysql/mysql.sock # 設置mysql的安裝目錄, 這裏的目錄必定要是你解壓後而且改了名的目錄喲.. basedir=/usr/local/mysql-5.5.62 # 設置mysql數據庫的數據的存放目錄, 這裏的目錄必定要是你解壓後而且改了名的目錄喲.. datadir=/usr/local/mysql-5.5.62/data # 容許最大鏈接數 max_connections=200 # 服務端使用的字符集默認爲8比特編碼的latin1字符集 character-set-server=utf8 # 建立新表時將使用的默認存儲引擎 default-storage-engine=INNODB lower_case_table_name=1 max_allowed_packet=16M
cd /usr/local/mysql-5.5.62
注意 : 這裏須要將目錄切換到mysql目錄下 也就是上一步的操做
groupadd mysql
useradd -g mysql mysql
chown -R mysql:mysql ./
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.5.62/ --datadir=/usr/local/mysql-5.5.62/data/
安裝後會有以下的打印
[root@yangtuo mysql-5.5.62]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.5.62/ --datadir=/usr/local/mysql-5.5.62/data/ Installing MySQL system tables... 190616 17:56:34 [Warning] Using unique option prefix lower_case_table_name instead of lower_case_table_names is deprecated and will be removed in a future release. Please use the full name instead. 190616 17:56:34 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 190616 17:56:34 [Note] /usr/local/mysql-5.5.62//bin/mysqld (mysqld 5.5.62) starting as process 73351 ... OK Filling help tables... 190616 17:56:34 [Warning] Using unique option prefix lower_case_table_name instead of lower_case_table_names is deprecated and will be removed in a future release. Please use the full name instead. 190616 17:56:34 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 190616 17:56:34 [Note] /usr/local/mysql-5.5.62//bin/mysqld (mysqld 5.5.62) starting as process 73359 ... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/local/mysql-5.5.62//bin/mysqladmin -u root password 'new-password' /usr/local/mysql-5.5.62//bin/mysqladmin -u root -h 172.20.10.7 192.168.122.1 password 'new-password' Alternatively you can run: /usr/local/mysql-5.5.62//bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /usr/local/mysql-5.5.62/ ; /usr/local/mysql-5.5.62//bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /usr/local/mysql-5.5.62//mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ [root@yangtuo mysql-5.5.62]#
以上到此已經安裝成功了 mysql 還須要一些設置才能夠正常運行
chown -R mysql:mysql data chown 777 /etc.my.cnf cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld chmod +x /etc/rc.d/init.d/mysqld chkconfig --add mysqld chkconfig --list mysqld mkdir /var/lib/mysql chmod 777 /var/lib/mysql
service mysqld start
vi ~/.bash_profile
在文件最後面加入如下內容,並使用:wq保存
export PATH=$PATH:/usr/local/mysql-5.5.62/bin
source ~/.bash_profile
以上操做完成就既能夠正常使用 mysql 了, 爲了後期的方便使用, 咱們還要進行必定的優化設置已經安全性設置等
這時mysql沒有密碼, 當出現Enter password:時直接回車
mysql -uroot -p
mysql> use mysql mysql> update user set password=password('須要設置的密碼') where user='root' and host='localhost'; mysql> flush privileges;
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '剛纔設置的root密碼' WITH GRANT OPTION;
到此全部配置所有完畢. 可使用遠程工具進行登陸了