1. 程式人生 > >centos7安裝Mysql5.6

centos7安裝Mysql5.6

create enter com hang AI per please 刪除 替換

一. 卸載

  先卸載centos7自帶的mariadb數據庫(MariaDB數據庫管理系統是MySQL的一個分支),如果不卸載掉他的話,那麽我們安裝的mysql數據庫是運行不起來的!

  rpm -qa |grep mariadb

  rpm -e mariadb-libs-5.5.37-1.el7_0.x86_64 (替換為服務器自帶的數據庫)

  註:如果報錯了,那麽主要是因為沒有加 --nodeps 導致的依賴錯誤

   rpm -e --nodeps mariadb-libs-5.5.37-1.el7_0.x86_64或者 rpm -e mariadb-libs-5.5.37-1.el7_0.x86_64 --nodeps

二.下載rpm包

下載源文件   
wget http://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm
(這個版本是在https://dev.mysql.com/downloads/repo/yum/找到)

   rpm -ivh mysql-community-release-el6-5.noarch.rpm

  yum repolist enabled | grep "mysql.*-community.*" 查看是否有源文件

  技術分享圖片

   當這樣時,說明已經下好了

三.安裝Mysql

  輸入: yum -y install mysql-community-server 用yum方式安裝mysql(一路yes)

四.安裝成功後,將其加入開機啟動

  輸入:  systemctl enable mysqld

五.啟動mysql

 輸入: systemctl start mysqld

六.配置mysql

 輸入: mysql_secure_installationTE: 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...

七:進入 mysql

   mysql -uroot -p

八.開啟遠程訪問

   mysql>use mysql;

   mysql>GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456‘ WITH GRANT OPTION;(將root用戶開啟遠程訪問權限)

  開啟遠程訪問權限“%”代表所有人

  註意:在開啟遠程訪問權限後也有可能訪問不了,而報一個10060的錯誤

  這個錯誤一般來說都是因為服務器防火墻的原因,所以,需要將服務器的端口加入到監聽中

  /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

  保存設置

  /etc/init.d/iptables save

  

centos7安裝Mysql5.6