【軟件安裝】CentOS7安裝MariaDb(mysql_替代品安裝)

1、背景

Maria Db是流行的跨平臺MySQL數據庫管理系統的分支,被認為是MySQL 的完全替代品。Maria Db是由Sun在Sun Micro systems合并期間被Oracle收購后,于2009年由MySQL的一位原始開發人員創建的。今天,Maria Db由Maria Db Foundation和社區貢獻者維護和開發,
Maria Db將MySQL替換為Cent OS 7存儲庫中的默認數據庫系統。雖然將MySQL安裝到Cent OS 7并不困難,但是如果您只需要一個數據庫,建議使用Maria Db進行官方支持,并且與其他存儲庫軟件不兼容的可能性很小。

2、開始之前

  • 虛擬機是最好的伙伴,推薦安裝一個VM+CentOS 自己動手試試
$ 表示系統的一般權限,不用使用root 超級管理員權限配置。
要檢查您的主機名:
$ hostname -f
$ hostname

img

1.1 安裝開始

  • 第一個命令應顯示您的短主機名,第二個命令應顯示您的完全限定域名(FQDN)。

  • 更新您的系統:

$ sudo yum update
  • 安裝并啟動MariaDB
$ sudo yum install mariadb-server
  • 啟用MariaDB以在啟動時啟動,然后啟動該服務:
systemctl start mariadb
systemctl status mariadb
systemctl enable mariadb
  • 默認情況下,MariaDB將綁定到localhost(127.0.0.1)。

注意

允許在公共IP上不受限制地訪問MariaDB,但是您可以在/etc/my.cnf中通過修改bind-address參數來更改它偵聽的地址。如果您決定將MariaDB綁定到公共IP,則應實施僅允許來自特定IP地址連接的防火墻規則。

[root@centos001 ~]# systemctl start mariadb
[root@centos001 ~]# systemctl status mariadb
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-05-08 15:23:10 CST; 14s ago
  Process: 13148 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
  Process: 13069 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 13147 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─13147 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─13309 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb...

May 08 15:23:08 centos001 mariadb-prepare-db-dir[13069]: MySQL manual for more instructions.
May 08 15:23:08 centos001 mariadb-prepare-db-dir[13069]: Please report any problems at http://mariadb.org/jira
May 08 15:23:08 centos001 mariadb-prepare-db-dir[13069]: The latest information about MariaDB is available at http://mariadb.org/.
May 08 15:23:08 centos001 mariadb-prepare-db-dir[13069]: You can find additional information about the MySQL part at:
May 08 15:23:08 centos001 mariadb-prepare-db-dir[13069]: http://dev.mysql.com
May 08 15:23:08 centos001 mariadb-prepare-db-dir[13069]: Consider joining MariaDB's strong and vibrant community:
May 08 15:23:08 centos001 mariadb-prepare-db-dir[13069]: https://mariadb.org/get-involved/
May 08 15:23:08 centos001 mysqld_safe[13147]: 190508 15:23:08 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
May 08 15:23:08 centos001 mysqld_safe[13147]: 190508 15:23:08 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
May 08 15:23:10 centos001 systemd[1]: Started MariaDB database server.
[root@centos001 ~]#


 

1.2 最后檢測

安裝完成之后,運行一下命令,進入數據庫,默認不需要密碼
$ mysql -uroot -p

 img

 - 查詢數據庫列表

[root@centos001 ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, 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)]>
 

img

安裝到此結束,余下是介紹如何使用配置


3、初始化配置,MariaDB的相關簡單配置

  • 接下來進行
$  mysql_secure_installation
  • 首先是設置密碼,會提示先輸入密碼
Enter current password for root (enter for none):<–初次運行直接回車
  • 設置密碼
Set root password? [Y/n] <– 是否設置root用戶密碼,輸入y并回車或直接回車
New password: <– 設置root用戶的密碼
Re-enter new password: <– 再輸入一次你設置的密碼
  • 其他配置
Remove anonymous users? [Y/n] <– 是否刪除匿名用戶,回車
Disallow root login remotely? [Y/n] <–是否禁止root遠程登錄,Y 回車,
Remove test database and access to it? [Y/n] <– 是否刪除test數據庫, N回車
Reload privilege tables now? [Y/n] <– 是否重新加載權限表,Y 回車

  • 我的設置,設置錯了再來一次

img

初始化MariaDB完成,接下來測試登錄,輸入一下命令和密碼 登錄進去

$ mysql -u root -p 

img

4、操作不會請輸入Help

要為MariaDB提示生成命令列表,請輸入\h。然后你會看到:


   List of all MySQL commands:
   Note that all text commands must be first on line and end with ';'
   ?         (\?) Synonym for `help'.
   clear     (\c) Clear the current input statement.
   connect   (\r) Reconnect to the server. Optional arguments are db and host.
   delimiter (\d) Set statement delimiter.
   edit      (\e) Edit command with $EDITOR.
   ego       (\G) Send command to mysql server, display result vertically.
   exit      (\q) Exit mysql. Same as quit.
   go        (\g) Send command to mysql server.
   help      (\h) Display this help.
   nopager   (\n) Disable pager, print to stdout.
   notee     (\t) Don't write into outfile.
   pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
   print     (\p) Print current command.
   prompt    (\R) Change your mysql prompt.
   quit      (\q) Quit mysql.
   rehash    (\#) Rebuild completion hash.
   source    (\.) Execute an SQL script file. Takes a file name as an argument.
   status    (\s) Get status information from the server.
   system    (\!) Execute a system shell command.
   tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
   use       (\u) Use another database. Takes database name as argument.
   charset   (\C) Switch to another charset. Might be needed for processing            binlog with multi-byte charsets.
   warnings  (\W) Show warnings after every statement.
   nowarning (\w) Don't show warnings after every statement.
   
   For server side help, type 'help contents'
   
   MariaDB [(none)]>

5 重置MariaDB Root密碼

** 如果您忘記了root 密碼,則可以重置密碼。**

  • 停止當前的MariaDB服務器實例,然后使用不要求輸入密碼的選項重新啟動它:
   sudo systemctl stop mariadb
   sudo mysqld_safe --skip-grant-tables &
  • 使用MariaDB root帳戶重新連接到MariaDB服務器:
   mysql -u root
  • 使用以下命令重置root的密碼。用強密碼替換password
   use mysql;
   update user SET PASSWORD=PASSWORD("password") WHERE USER='root';
   flush privileges;
   exit
  • 然后重啟MariaDB:
   sudo systemctl start mariadb
posted @ 2020-07-17 09:48  sopcce  閱讀(19)  評論(0編輯  收藏
最新chease0ldman老人