MariaDB

来自Gea-Suan Lin's Wiki
跳转到导航 跳转到搜索

MariaDBMySQL的分支版本之一。

安装

Debian的testing上安装可以直接安装系统版本,通常都是最新版:

sudo apt install -y mariadb-server; sudo apt clean; sudo service mysql stop; cd /etc/mysql/mariadb.conf.d; sudo mv 50-server.cnf 50-server.cnf.bak; sudo wget -O 50-server.cnf https://raw.githubusercontent.com/gslin/mysql-template/master/mariadb-11.4.cnf; sudo mkdir /srv/tmp; sudo chmod 1777 /srv/tmp; sudo service mysql start

Ubuntu上系统内的MariaDB不保证是最新版,所以会透过MariaDB官方提供的套件库安装。目前MariaDB是目前最新的LTS版本是11.4(前一个LTS是10.11),可以到MariaDB Server Releases这边查询有没有更新的LTS版本:

sudo mkdir -p /etc/apt/keyrings; sudo curl -o /etc/apt/keyrings/mariadb-keyring.pgp https://mariadb.org/mariadb_release_signing_key.pgp; echo "deb [signed-by=/etc/apt/keyrings/mariadb-keyring.pgp] https://mirror.rackspace.com/mariadb/repo/11.4/ubuntu $(lsb_release -c -s) main" | sudo tee /etc/apt/sources.list.d/mariadb.list; sudo apt update; sudo apt install -y mariadb-server; sudo apt clean; sudo service mysql stop; cd /etc/mysql/mariadb.conf.d; sudo mv 50-server.cnf 50-server.cnf.bak; sudo wget -O 50-server.cnf https://raw.githubusercontent.com/gslin/mysql-template/master/mariadb-11.4.cnf; sudo mkdir /srv/tmp; sudo chmod 1777 /srv/tmp; sudo service mysql start

另外可以加装mycli:

sudo apt install -y mycli; sudo apt clean

刚装好时是透过档案权限保护unix socket,所以可以透过sudo存取:

sudo mariadb -u root

接下来设定root密码,以便后续可以不需要sudo,用与MySQL相同的方法登入:

echo "SET PASSWORD = PASSWORD('password');" | sudo mariadb -u root

比较特别的地方是,在有设定skip-name-resolve时(在我上面安装的template里面有,算是MySQL系常见的设定),透过mysql -h 127.0.0.1连线的使用者不会算在username@localhost的账号,而会需要另外设定一组username@%,像是这样:

CREATE USER `trac`@`%` IDENTIFIED BY 'password_here';
GRANT ALL ON trac.* TO `trac`@`%`;

相关连结

外部链接