Manjaro 安裝 mariadb 數據庫

sudo pacman -S mariadb
sudo chmod -R 777 /var/lib/mysql
注:這個目錄必須可讀寫,不然會報錯,因爲涉及到數據存儲。


例如


sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...
2019-10-11 15:17:42 0 [ERROR] InnoDB: Invalid flags 0x4800 in ./ibdata1
2019-10-11 15:17:42 0 [ERROR] InnoDB: Plugin initialization aborted with error Data structure corruption
2019-10-11 15:17:43 0 [ERROR] Plugin 'InnoDB' init function returned error.
2019-10-11 15:17:43 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2019-10-11 15:17:43 0 [ERROR] Unknown/unsupported storage engine: InnoDB
2019-10-11 15:17:43 0 [ERROR] Aborting
正確的是這樣


sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system


Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is mysql@localhost, it has no password either, but
you need to be the system 'mysql' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo

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

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

systemctl start mariadb
開啓服務
或着直接進入目錄,啓動。
安全配置嚮導

mysql_secure_installation
或者
/usr/bin/mysql_secure_installation

設置用戶名密碼
[k@k-pc ~]$ sudo mysql_secure_installation
必須用管理員
[sudo] k 的密碼:

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
haven't set the root password yet, you should just press enter here.

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

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

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] y
Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the 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]
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] 



禁止root遠程登錄,直接yes,安全
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?
刪除test數據庫,看個人需要了
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now?
重新加載權限表,直接回車
最後

[k@k-pc ~]$ sudo 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.4.8-MariaDB Arch Linux

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)]> 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章