在中国安装MariaDB的方法是通过homebrew
稍微总结了一下尝试在Macbook上安装MariaDB的经历。
首先,确认一下我们一直依赖的 homebrew 中是否有这个软件包。
$ brew update
$ brew search mariadb
mariadb
$ brew info mariadb
mariadb: stable 10.0.12 (bottled)
MariaDB Foundation
Conflicts with: mysql, mysql-cluster, mysql-connector-c, percona-server
Not installed
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/mariadb.rb
==> Dependencies
Build: cmake ✘
==> Options
--enable-local-infile
Build with local infile loading support
--universal
Build a universal binary
--with-archive-storage-engine
Compile with the ARCHIVE storage engine enabled
--with-bench
Keep benchmark app when installing
--with-blackhole-storage-engine
Compile with the BLACKHOLE storage engine enabled
--with-embedded
Build the embedded server
--with-libedit
Compile with editline wrapper instead of readline
--with-tests
Keep test when installing
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.
To connect:
mysql -uroot
To have launchd start mariadb at login:
ln -sfv /usr/local/opt/mariadb/*.plist ~/Library/LaunchAgents
Then to load mariadb now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
Or, if you don't want/need launchctl, you can just run:
mysql.server start
考虑到MariaDB也确实在homebrew中进行了准备,因此我会感激地使用homebrew安装。
$ brew install mariadb
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/mariadb-10.0.12.mavericks.bottle.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/mariadb-10.0.12.mavericks.bottle.1.tar.gz
==> Pouring mariadb-10.0.12.mavericks.bottle.1.tar.gz
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.
To connect:
mysql -uroot
To have launchd start mariadb at login:
ln -sfv /usr/local/opt/mariadb/*.plist ~/Library/LaunchAgents
Then to load mariadb now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
Or, if you don't want/need launchctl, you can just run:
mysql.server start
WARNING: launchctl will fail when run under tmux.
==> Summary
? /usr/local/Cellar/mariadb/10.0.12: 519 files, 125M
安装完成了。(每次都想,安装完成后出现的那个啤酒标志是什么意思呢…)
MariaDB 的最低限度设置是 mysql_secure_installation。
可以通过homebrew等方式安装的mariadb,但为了进行最基本的安全设置,建议执行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):
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):
根目录的密码(默认为空,可以直接按回车键)
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.
You already have a root password set, so you can safely answer 'n'.
Change the root password? [Y/n] <-- root のパスワード変更するなら y で Enter
New password: <-- 何かパスワード
Re-enter new password: <-- もう一回
在这里更改root用户的密码
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用户限制为仅从本地主机连接。是的,这是可以实现的。本地专用的root用户限制在仅从本地主机(localhost)进行连接,因此您可以将其留空并按Enter键进入。
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]
默認情况下存在名为test的数据库,但是因为不需要而希望保持为空,请输入test后删除数据库。
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n]
当空白的时候,按下Enter键来应用设置的话…
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
准备工作完成!要启动,请执行以下命令。
> mysql -u root -p
Enter password:
当输入此命令并输入设置的密码时
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 27
Server version: 10.0.12-MariaDB Homebrew
Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
从这里可以确认是否能够正确连接到mariadb。
使用Homebrew安装的MariaDB的my.conf文件的位置。使用命令查找路径,结果如下:
> mysql --help | grep cnf
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf
order of preference, my.cnf, $MYSQL_TCP_PORT,
> mysql --help | grep cnf
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf
order of preference, my.cnf, $MYSQL_TCP_PORT,
实际上,homebrew安装的mariadb的配置文件存在于/usr/local/etc/my.cnf中。
实际上看看里面的内容…
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
#
# include all files from the config directory
#
!includedir /usr/local/etc/my.cnf.d
作为规矩,请将设置文件放在 /usr/local/etc/my.cnf.d 文件夹中。
我的.conf文件基本配置文件等。就像MySQL一样,预先准备了作为自己my.cnf基本文件的文件。
> ls $(brew --prefix mariadb)/support-files/my-*
/usr/local/opt/mariadb/support-files/my-huge.cnf /usr/local/opt/mariadb/support-files/my-medium.cnf
/usr/local/opt/mariadb/support-files/my-innodb-heavy-4G.cnf /usr/local/opt/mariadb/support-files/my-small.cnf
/usr/local/opt/mariadb/support-files/my-large.cnf
> ls $(brew --prefix mariadb)/support-files/my-*
/usr/local/opt/mariadb/support-files/my-huge.cnf /usr/local/opt/mariadb/support-files/my-medium.cnf
/usr/local/opt/mariadb/support-files/my-innodb-heavy-4G.cnf /usr/local/opt/mariadb/support-files/my-small.cnf
/usr/local/opt/mariadb/support-files/my-large.cnf
如果需要准备这样的基于 MySQL 的配置文件,请将该文件复制到 /usr/local/etc/my.cnf.d 文件夹及其子文件夹中,并添加自定义设置。
关于多语言支持。
当实际从homebrew安装的mariadb的语言设置如何,进行调查发现。。。
MariaDB [(none)]> show variables like 'char%';
+--------------------------+---------------------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/Cellar/mariadb/10.0.12/share/mysql/charsets/ |
+--------------------------+---------------------------------------------------------+
8 rows in set (0.00 sec)
MariaDB [(none)]> show variables like 'char%';
+--------------------------+---------------------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/Cellar/mariadb/10.0.12/share/mysql/charsets/ |
+--------------------------+---------------------------------------------------------+
8 rows in set (0.00 sec)
从一开始,似乎就是utf8编码,所以不需要添加任何设置就可以显示日语。
如果character_set_server设置为latin1的话(在CentOS或Debian上安装时,默认可能是latin1编码……),需要在配置文件(如my.cnf)中进行相应设置。
[mysqld] <-- mysqld の箇所を探して
character-set-server = utf8 <-- この設定を加える
如果更改(添加)了设置的话,请使用以下命令重新启动。
> mysql.server restart
Shutting down MySQL
.. SUCCESS!
Starting MySQL
. SUCCESS!