[daily][mariadb][mysql] mariadb快速設置

 

參考: https://wiki.archlinux.org/index.php/MySQLphp

1. 安裝html

使用pacman常規安裝mysql

 

2. btrfs 禁用CoWlinux

mariadb的數據文件若是存儲在btrfs上的話, 則須要一步特殊的設置sql

http://www.cnblogs.com/hugetong/p/8459518.html數據庫

 

3. 安裝數據庫網絡

┬─[tong@T7:~/Data/anthropoid]─[05:57:38 PM]
╰─>$ sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql/

 

4.  啓動數據庫socket

┬─[tong@T7:~/Data/anthropoid]─[06:04:44 PM]
╰─>$ sudo systemctl start mariadb.service
┬─[tong@T7:~/Data/anthropoid]─[06:04:59 PM]
╰─>$ sudo systemctl status mariadb.service
● mariadb.service - MariaDB 10.1.31 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2018-02-22 18:04:59 CST; 6s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 17440 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 17359 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSITION=$VA
  Process: 17358 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 17412 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 27 (limit: 4915)
   CGroup: /system.slice/mariadb.service
           └─17412 /usr/bin/mysqld

Feb 22 18:04:59 T7 mysqld[17412]: 2018-02-22 18:04:59 140256265457600 [Note] InnoDB: Highest supported file format is Barracuda.
Feb 22 18:04:59 T7 mysqld[17412]: 2018-02-22 18:04:59 140256265457600 [Note] InnoDB: 128 rollback segment(s) are active.
Feb 22 18:04:59 T7 mysqld[17412]: 2018-02-22 18:04:59 140256265457600 [Note] InnoDB: Waiting for purge to start
Feb 22 18:04:59 T7 mysqld[17412]: 2018-02-22 18:04:59 140256265457600 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.36-83.0 started; log sequence number 1616717
Feb 22 18:04:59 T7 mysqld[17412]: 2018-02-22 18:04:59 140256265457600 [Note] Plugin 'FEEDBACK' is disabled.
Feb 22 18:04:59 T7 mysqld[17412]: 2018-02-22 18:04:59 140255641392896 [Note] InnoDB: Dumping buffer pool(s) not yet started
Feb 22 18:04:59 T7 mysqld[17412]: 2018-02-22 18:04:59 140256265457600 [Note] Server socket created on IP: '::'.
Feb 22 18:04:59 T7 mysqld[17412]: 2018-02-22 18:04:59 140256265457600 [Note] /usr/bin/mysqld: ready for connections.
Feb 22 18:04:59 T7 mysqld[17412]: Version: '10.1.31-MariaDB'  socket: '/run/mysqld/mysqld.sock'  port: 3306  MariaDB Server
Feb 22 18:04:59 T7 systemd[1]: Started MariaDB 10.1.31 database server.

 

5. 設置密碼之類的tcp

┬─[tong@T7:~/Data/anthropoid]─[06:09:05 PM]
╰─>$ mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

 

6. 能夠用了ide

┬─[tong@T7:~/Data/anthropoid]─[06:10:23 PM]
╰─>$ mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.1.31-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)]> 

 

7. 禁止遠程訪問數據庫

由於我就是爲了使用gnucash, 本地使用就夠了.

┬─[tong@T7:~/Data/anthropoid]─[06:12:40 PM]
╰─>$ sudo sed -i "s/#skip-networking/skip-networking/g" /etc/mysql/my.cnf 

改完配置,重啓服務, 發現監聽端口已經不在了.

─[tong@T7:~/Data/anthropoid]─[06:14:19 PM]
╰─>$ sudo netstat -nap |grep mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      17774/mysqld        
unix  2      [ ACC ]     STREAM     LISTENING     500225   17774/mysqld         /run/mysqld/mysqld.sock
unix  3      [ ]         STREAM     CONNECTED     500197   17774/mysqld         
┬─[tong@T7:~/Data/anthropoid]─[06:15:32 PM]
╰─>$ sudo systemctl restart mariadb.service
┬─[tong@T7:~/Data/anthropoid]─[06:15:54 PM]
╰─>$ sudo netstat -nap |grep mysqld
unix  2      [ ACC ]     STREAM     LISTENING     516313   18695/mysqld         /run/mysqld/mysqld.sock
unix  3      [ ]         STREAM     CONNECTED     517433   18695/mysqld         

 

8. 設置自啓動

┬─[tong@T7:~/Data/anthropoid]─[06:15:59 PM]
╰─>$ sudo systemctl enable mariadb.service
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.

 

9. 建立數據庫

見文檔:https://mariadb.com/kb/en/library/create-database/

其中,須要注意的是字符集問題, 見: https://mariadb.com/kb/en/library/setting-character-sets-and-collations/

character-sets很好理解, 可是collations是什麼? 用來排序比較大小? 好吧....

https://mariadb.com/kb/en/library/character-set-and-collation-overview/

A character set is a set of characters while a collation is the rules for comparing and sorting a particular character set.

 

然而, 在arch上,個人默認就是UTF8MB4, 因此直接create database就好了.

MariaDB [mysql]> show variables like "character_set_server";
+----------------------+---------+
| Variable_name        | Value   |
+----------------------+---------+
| character_set_server | utf8mb4 |
+----------------------+---------+
1 row in set (0.00 sec)

MariaDB [mysql]> show variables like "collation_server";
+------------------+--------------------+
| Variable_name    | Value              |
+------------------+--------------------+
| collation_server | utf8mb4_unicode_ci |
+------------------+--------------------+
1 row in set (0.00 sec)

另外, 有關utf8MB4

 

嗯, 而後建立gnucash的數據庫.

MariaDB [mysql]> create database gnucash;
Query OK, 1 row affected (0.01 sec)

MariaDB [mysql]> show create database gnucash;
+----------+------------------------------------------------------------------------------------------------+
| Database | Create Database                                                                                |
+----------+------------------------------------------------------------------------------------------------+
| gnucash  | CREATE DATABASE `gnucash` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */ |
+----------+------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

 

10 建立gnucash用戶

文檔: https://mariadb.com/kb/en/library/create-user/

建立用戶比建立數據庫要稍微複雜一些.

a. account name

Account names have both a user name and a host name, and are specified as 'user_name'@'host_name'.

When you connect to a MariaDB server, your user name and host must match a single account.

The user name and host name may be unquoted, quoted as strings using double quotes (") or single quotes ('), or quoted as identifiers using backticks (`). 
You must use quotes when using special characters (such as a hyphen) or wildcard characters. If you quote, you must quote the user name and host
name separately (for example 'user_name'@'host_name').
If the host name is not provided, it is assumed to be '%'.
User names must match exactly, including case. You can use the empty string to allow a user with any user name.

建!

MariaDB [mysql]> create user 'gnucash'@'localhost' identified by 'xxxxyyy'
    -> ;
Query OK, 0 rows affected (0.00 sec)

b. grant

https://mariadb.com/kb/en/library/grant/

MariaDB [mysql]> grant all privileges on gnucash.* to 'gnucash'@'localhost'
    -> ;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 

11 GUI client

找了好多, 除了phpmyadmin, 只有dbeaver能夠用... 並且免費.... 可是phpmyadmin須要配http server, 因此仍是用dbeaver.

可是dbeaver不能連接本地socket, 必須經過網絡,開監聽.

$ yaourt -S dbeaver
相關文章
相關標籤/搜索