centos7 安裝mariadb

centos7 安裝mariadb

一、使用國內源:
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-
Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo
http://mirrors.aliyun.com/repo/Centos-7.repo

二、安裝mariadb
yum -y install mariadb mariadb-server mariadb-devel

三、cat /etc/my.cnf
[mysqld]

default-storage-engine = innodb
innodb_file_per_table
collation-server = utf8_general_ci
init-connect = 'SET NAMES utf8'
character-set-server = utf8

四、啓動mariadb
root用戶直接啓動,由於我的環境是vagrant ssh連接的,默認的是vagrant用戶

systemctl start mariadb    #用root用戶啓動,非root用戶需要sudo
mysql

進入mariadb:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, 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 |
| test |
+--------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> select * from mysql.user \G
ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for table 'user'
#這裏就2個庫,mysql庫看不到,當然也查看不了
MariaDB [(none)]> select user();
+-------------------+
| user() |
+-------------------+
| vagrant@localhost |
+-------------------+
1 row in set (0.00 sec)
#看到 當前登錄的用戶是,因爲剛纔是mysql 直接進來的,此時我們要給mariadb配置初始密碼;
mysqladmin -u root password #設置root密碼。

再來,這次不直接mysql進來了
mysql -uroot -p
這裏輸入剛纔的密碼

進來了
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> select * from mysql.user \G 正常查詢

忘記root密碼:

  • systemctl stop mariadb 先關閉服務
  • su - root 切到系統root用戶
  • mysqld_safe --skip-grant-tables & 跳過認證啓動服務
  • mysql mysql進入服務
  • use mysql 切換到mysql庫
  • UPDATE user SET password=password('heheda') WHERE user='root';
  • flush privileges;
  • ps -ef |grep mysql|grep -v grep |awk '{print $2}'|xargs kill -9
  • systemctl start mariadb
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章