centos7.2使用yum安裝mysql
一、系統環境
[[email protected] home]# cat /etc/RedHat-release
CentOS Linux release 7.2.1511 (Core)
二、mysql安裝
安裝mysql和mysql-devel都成功,但是安裝mysql-server失敗,如下:
[[email protected] home]# yum install mysql-server 沒有可用軟體包 mysql-server。 錯誤:無須任何處理
出現這樣問題是CentOS 7 版本將MySQL資料庫軟體從預設的程式列表中移除,用mariadb代替了
有兩種解決辦法:
1、方法一:官網下載安裝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] lzh]# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server 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 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.01 sec)
設定密碼
mysql> set password for 'root'@'localhost' =password('password'); Query OK, 0 rows affected (0.00 sec)
安裝完以後mariadb自動就被替換了,將不再生效。
[[email protected] lzh]# rpm -qa |grep mariadb
2、方法二:安裝mariadb
MariaDB資料庫管理系統是MySQL的一個分支,採用GPL授權許可 MariaDB的目的是完全相容MySQL,包括API和命令列,使之能輕鬆成為MySQL的代替品。MariaDB由MySQL的創始人Michael Widenius(英語:Michael Widenius)主導開發,他早前將自己建立的公司MySQL AB賣給了SUN,此後,隨著SUN被甲骨文收購,MySQL的所有權也落入
安裝mariadb,輸入安裝命令
[[email protected] home]# 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
預設無密碼
[[email protected] lzh]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 6 Server version: 5.5.52-MariaDB MariaDB Server Copyright (c) 2000, 2016, 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.01 sec)