Manjaro 安装mysql

安装Mariadb代替MySQL

1
sudo pacman -S mysql

初始化配置

  1. 初始化Mariadb
    1
    sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

输出提示信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'/usr/bin/mysqladmin' -u root password 'new-password'
'/usr/bin/mysqladmin' -u root -h sulang-pc password 'new-password'

Alternatively you can run:
'/usr/bin/mysql_secure_installation'

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '/usr' ; /usr/bin/mysqld_safe --datadir='/var/lib/mysql'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/mysql-test' ; perl mysql-test-run.pl

  1. 启动Mariadb

    1
    2
    systemctl start mariadb
    systemctl enable mariadb
  2. 设置root密码

    1
    mysql_secure_installation
  3. 配置文件加载读取顺序
    /etc/my.cnf -> /etc/mysql/my.cnf -> ~/.my.cnf

  1. 设置数据库编码UTF-8
    在 /etc/mysql/my.cnf 的 mysqld 下添加:
    1
    2
    3
    4
    5
    [mysqld]
    init_connect = 'SET collation_connection = utf8_general_ci,NAMES utf8'
    collation_server = utf8_general_ci
    character_set_client = utf8
    character_set_server = utf8

重启mariadb