CentOS7 安裝MySQL

這段時間在安裝mysql時候遇到點問題,原先的yum安裝安裝不上,因而本身採用rpm安裝mysql;mysql

mysql須要的rpm包下載地址:http://repo.mysql.com/yum/sql

選擇你本身想要安裝的版本,打開以後會是這樣的。數據庫

 

1. 首先清除centos7系統中默認的數據庫mariadb,不然不能安裝mysql。centos

rpm -qa |grep mariadb |xargs yum remove -y

2.下載mysql的相關rpm包安全

 

  關於下載問題,你能夠直接使用wget + 包的URL 下載到一個臨時文件(個人是/tmp/download文件)ide

 

 

   注意:每一個安裝包版本號是同樣的,不然後面安裝會出現問題;意味着每一個文件都是以5.7.19-1.el7.x86_64.rpm結尾的測試

3.切換到下載包目錄下(cd 你的下載目錄),而後對每一個包進行一次安裝;centos7

  rpm -ivh mysql-community-common-5.7.19-1.el7.x86_64.rpm 
  rpm -ivh mysql-community-libs-5.7.19-1.el7.x86_64.rpm 
  rpm -ivh mysql-community-libs-compat-5.7.19-1.el7.x86_64.rpm 
  rpm -ivh mysql-community-client-5.7.19-1.el7.x86_64.rpm 
  rpm -ivh mysql-community-server-5.7.19-1.el7.x86_64.rpm

 在安裝最後一個mysql-community-server的時候可能會出現下面的錯誤提示:spa

 

  解決這個問題是由於系統缺乏了libaio這個庫,咱們安裝好就能夠了。日誌

下載地址:http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm

這時候就能夠安裝mysql-community-server;

 

4.查看安裝mysql時候生成的臨時密碼,這個臨時密碼放在了mysql日誌文件中了。(對於Mysql 5.7.6之後的5.7系列版本,Mysql使用mysqld --initialize或mysqld --initialize-insecure命令來初始化數據庫,後者能夠不生成臨時密碼。)

[root@localhost ~]# cat /etc/my.cnf  

 log-error=/var/log/mysqld.log  --找到日誌路徑  

[root@localhost  ~]# cat /var/log/mysqld.log | grep password  --查到密碼爲PCbu?SNEx8zl  

 

[root@localhost  ~]# /usr/bin/mysql_secure_installation --安裝完mysql後執行自帶的安全設置  

    

 Securing the MySQL server deployment.  

  Enter password for user root:   --輸入剛找到的臨時密碼

   The existing password for the user account root has expired. Please set a new password.  

  New password:     --設置新的密碼

  Re-enter new password:   

  The 'validate_password' plugin is installed on the server.  

  The subsequent steps will run with the existing configuration  

  of the plugin.  

  Using existing password for root.  

  Estimated strength of the password: 100   

  Change the password for root ? ((Press y|Y for Yes, any other key for No) : y  

  New password:   

  Re-enter new password:   

  Estimated strength of the password: 100   

  Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y  

  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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y  --不容許遠程鏈接  

  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? (Press y|Y for Yes, any other key for No) : y  --移除測試數據庫  

   - Dropping test database...  

  Success.  

   - 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? (Press y|Y for Yes, any other key for No) : y  --重讀受權表使前面修改生效  

  Success.  

  All done!   

  

 [root@localhost ~]# mysql -u root -p   

   

 Enter password:   

  Welcome to the MySQL monitor.  Commands end with ; or \g.  

  Your MySQL connection id is 11  

  Server version: 5.7.17 MySQL Community Server (GPL)  

  Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.  

  Oracle is a registered trademark of Oracle Corporation and/or its  

  affiliates. Other names may be trademarks of their respective  

  owners.  

  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  

      mysql>

  

 5. 安裝成功!

相關文章
相關標籤/搜索