centos7 mysql資料庫安裝和配置

來源:互聯網
上載者:User

標籤:restart   0 rows   connect   資料庫   sina   方式   package   停止   usr   

一、系統內容

yum update升級以後的系統版本為

[[email protected] yl]# cat /etc/redhat-release CentOS Linux release 7.1.1503 (Core) 
二、mysql安裝

一般網上給出的資料都是

#yum install mysql#yum install mysql-server#yum install mysql-devel

安裝mysql和mysql-devel都成功,但是安裝mysql-server失敗,如下:

[[email protected] yl]# yum install mysql-serverLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.sina.cn * extras: mirrors.sina.cn * updates: mirrors.sina.cnNo package mysql-server available.Error: Nothing to do

查資料發現是CentOS 7 版本將MySQL資料庫軟體從預設的程式列表中移除,用mariadb代替了。

有兩種解決辦法:

1、方法一:安裝mariadb

MariaDB資料庫管理系統是MySQL的一個分支,主要由開源社區在維護,採用GPL授權許可。開發這個分支的原因之一是:甲骨文公司收購了MySQL後,有將MySQL閉源的潛在風險,因此社區採用分支的方式來避開這個風險。MariaDB的目的是完全相容MySQL,包括API和命令列,使之能輕鬆成為MySQL的代替品。

安裝mariadb,大小59 M。

[[email protected] yl]# yum install mariadb-server mariadb 

mariadb資料庫的相關命令是:

systemctl start mariadb  #啟動MariaDB

systemctl stop mariadb  #停止MariaDB

systemctl restart mariadb  #重啟MariaDB

systemctl enable mariadb  #設定開機啟動

所以先啟動資料庫

[[email protected] yl]# systemctl start mariadb

然後就可以正常使用mysql了

[[email protected] yl]# mysql -u root -pEnter password: Welcome to the MariaDB monitor.  Commands end with ; or \g.Your MariaDB connection id is 3Server version: 5.5.41-MariaDB MariaDB ServerCopyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.MariaDB [(none)]> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || test               |+--------------------+4 rows in set (0.00 sec)MariaDB [(none)]> 

安裝mariadb後顯示的也是 MariaDB [(none)]> ,可能看起來有點不習慣。下面是第二種方法。

2、方法二:官網下載安裝mysql-server
# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm# rpm -ivh mysql-community-release-el7-5.noarch.rpm# yum install mysql-community-server

安裝成功後重啟mysql服務。

# service mysqld restart

初次安裝mysql,root賬戶沒有密碼。

[[email protected] yl]# mysql -u root Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.6.26 MySQL Community Server (GPL)Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || test               |+--------------------+4 rows in set (0.01 sec)mysql> 

設定密碼

mysql> set password for ‘root‘@‘localhost‘ =password(‘password‘);Query OK, 0 rows affected (0.00 sec)mysql> 

不需要重啟資料庫即可生效。

在mysql安裝過程中如下內容:

Installed:
  mysql-community-client.x86_64 0:5.6.26-2.el7                mysql-community-devel.x86_64 0:5.6.26-2.el7                
  mysql-community-libs.x86_64 0:5.6.26-2.el7                  mysql-community-server.x86_64 0:5.6.26-2.el7               

Dependency Installed:
  mysql-community-common.x86_64 0:5.6.26-2.el7                                                                            

Replaced:
  mariadb.x86_64 1:5.5.41-2.el7_0          mariadb-devel.x86_64 1:5.5.41-2.el7_0   mariadb-libs.x86_64 1:5.5.41-2.el7_0  
  mariadb-server.x86_64 1:5.5.41-2.el7_0 

所以安裝完以後mariadb自動就被替換了,將不再生效。

[[email protected] yl]# rpm -qa |grep mariadb[[email protected] yl]# 
三、配置mysql1、編碼

mysql設定檔為/etc/my.cnf

最後加上編碼配置

[mysql]default-character-set =utf8

這裡的字元編碼必須和/usr/share/mysql/charsets/Index.xml中一致。

2、遠端連線設定

把在所有資料庫的所有表的所有許可權賦值給位於所有IP地址的root使用者。

mysql> grant all privileges on *.* to [email protected]‘%‘identified by ‘password‘;

如果是新使用者而不是root,則要先建立使用者

mysql>create user ‘username‘@‘%‘ identified by ‘password‘;  

此時就可以進行遠端連線了。

 

centos7 mysql資料庫安裝和配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.