Linux安裝配置Mariadb

2022-01-30 13:07:17 字數 2824 閱讀 4066

參考:

從最新版本的

linux系統

開始,預設的是 mariadb而不是

mysql

!使用系統自帶的repos安裝很簡單:

檢視並解除安裝原有的:

查詢所安裝的mariadb元件:

[root@localhost logs]# rpm -qa | grep maria*

mariadb-server-5.5.49-1.el7.centos.x86_64

mariadb-common-5.5.49-1.el7.centos.x86_64

mariadb-client-5.5.49-1.el7.centos.x86_64

解除安裝資料庫:

[root@localhost logs]# yum -y remove mari*

刪除資料庫檔案:

[root@localhost logs]# rm -rf /var/lib/mysql/*

yum install -y mariadb mariadb-server

systemctl start mariadb ==> 啟動

mariadb

systemctl enable mariadb ==> 開機自啟動

mysql -uroot -p123456 ==> 測試登入!

結束!這裡針對的是知道 root 密碼,而需要修改的情況。

兩種修改方法:

1、直接在shell命令列使用 mysqladm 命令修改。

# mysqladmin -uroot -poldpassword password newpassword 這種方法的弊端在於會明文顯示密碼。

2、登陸資料庫修改密碼。

# mysql -uroot -p 2.1 更新 mysql 庫中 user 表的字段: mariadb [(none)]> use mysql;   mariadb [mysql]> update user set password=password('123456') where user='root';   mariadb [mysql]> flush privileges;   mariadb [mysql]> exit; 2.2 或者,使用 set 指令設定root密碼: mariadb [(none)]> set password for 'root'@'localhost'=password('newpassword');   mariadb [(none)]> exit;

如果是忘記了 root 密碼,則需要以跳過授權的方式啟動 mariadb 來修改密碼。

1、先停掉服務。

# systemctl stop mariadb

2、使用跳過授權的方式啟動 mariadb。

# mysqld_safe --skip-grant-tables & [1] 1441 [root@centos7 ~]# 170531 02:10:28 mysqld_safe logging to '/var/log/mariadb/mariadb.log'. 170531 02:10:28 mysqld_safe starting mysqld daemon with databases from /var/lib/mysql # ps -ef | grep 1441 root      1441   966  0 02:10 pts/0    00:00:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables mysql     1584  1441  0 02:10 pts/0    00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-grant-tables --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock

3、當跳過授權啟動時,可以不需要密碼直接登陸資料庫。登陸更新密碼即可。

# mysql mariadb [(none)]> use mysql;   mariadb [mysql]> update user set password=password('newpassword') where user='root';   mariadb [mysql]> flush privileges;    mariadb [mysql]> exit; 更新密碼後,在跳過授權啟動時也不能空密碼直接登陸了。

4、關閉跳過授權啟動的程序:

# kill -9 1441

5、正常啟動 mariadb:

# systemctl start mariadb

三、設定user

建立user:

create user 'test'@'localhost' identified by '123456';

修改許可權:

grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;

修改許可權。%表示針對所有ip,

password

表示將用這個密碼登入

root

使用者,如果想只讓某個

ip段的主機連線,可以修改為

grant all privileges on *.* to 'root'@'192.168.100.%' identified by 'my-new-password' with grant option;

CentOS用yum安裝 配置MariaDB

1.建立 etc yum.repos.d mariadb.repo檔案,這裡用到了剛剛發布正式版的10.0 mariadb name mariadb baseurl gpgkey gpgcheck 1 2.準備好repo檔案後可以使用yum來安裝了 yum install mariadb serve...

linux安裝配置mysql

利用上篇已經配置好的yum來安裝mysql 1 安裝檢視有沒有安裝過 yum list installed mysql rpm qa grep mysql 2 檢視有沒有安裝包 yum list mysql 3 安裝mysql客戶端 yum install mysql 4 安裝mysql 伺服器端 ...

Linux安裝配置php

1.獲取安裝檔案 php 5.3.8.tar.gz 獲取安裝php需要的支援檔案 libxml2 2.6.32.tar.gz 2.安裝libxml2 1 tar zxvf libxml2 2.6.32.tar.gz 2 cd libxml2 2.6.32 3 configure prefix usr...