如何在香港服务器中安装MariaDB
MariaDB是流行的跨平台MySQL数据库管理系统的分支,被认为是MySQL完全替代品。由于Oracle在Sun Microsystems合并期间收购了MySQL后,MariaDB于2009年由MySQL的起始开发人员创建。MariaDB可以提供给我们新世界主机香港服务器的用户更多的数据库选择,所以今天小编就给大家介绍如何在CentOS行安装配置MariaDB。
(一)在开始之前:
1. 置了Linode的主机名。检查您的主机名运行:
#hostname
#hostname -f
第一个命令应显示您的短主机名,第二个命令应显示您的完全限定域名(FQDN)。
2.更新系统
#sudo yum update
(二)安装并启动MariaDB
1.安装
sudo yum install mariadb-server
2.启动MariaDB启动,然后启动服务:
sudo systemctl启用mariadb
sudo systemctl启动mariadb
默认情况下,MariaDB将绑定到localhost(127.0.0.1),有关使用SSH连接到远程数据库的信息。
(三)硬化MariaDB服务器
运行mysql_secure_installation脚本以解决默认MariaDB安装中的几个安全问题:
sudo mysql_secure_installation
您将可以选择更改MariaDB根密码,删除匿名用户帐户,禁用本地主机以外的root登录名,并删除测试数据库。建议您回答yes这些选项。您可以在MariaDB知识库中阅读有关该脚本的更多信息。
(四)使用MariaDB
与MariaDB交互的标准工具是mariadb客户端,它与mariadb-server软件包一起安装。MariaDB客户端通过终端使用。
1.根登录
以root用户身份登录到MariaDB:
mysql -u root –p
出现提示时,输入mysql_secure_installation脚本运行时分配的root密码。然后,您将看到一个欢迎标题和MariaDB提示符,如下所示:
MariaDB [(null)]>
要生成MariaDB提示符的命令列表,请输入\h。你会看到(仅展示部分):
List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
(\) Synonym for `help'.
clear (\c) Clear the current input statement.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit (\e) Edit command with $EDITOR.
ego (\G) Send command to mysql server, display result vertically.
exit (\q) Exit mysql. Same as quit.
go (\g) Send command to mysql server.
help (\h) Display this help.
nopager (\n) Disable pager, print to stdout.
notee (\t) Don't write into outfile.
pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print (\p) Print current command.
prompt (\R) Change your mysql prompt.
quit (\q) Quit mysql.
(五)创建一个新的MariaDB用户和数据库
在下面的例子中,testdb是数据库的名称,testuser是用户,password是用户的密码:
create database testdb;
create user 'testuser'@localhost identified by 'password';
grant all on testdb.* to 'testuser' identified by 'password';
您可以通过在分配数据库权限的同时创建用户来缩短此过程:
create database testdb;
grant all on testdb.* to 'testuser' identified by 'password';
然后退出MariaDB:
Exit
(六) 创建一个样本表
1.重新登录为testuser:
mysql -u testuser -p
2. 创建一个调用的示例表customers。这将创建一个表,其客户ID字段INT为整数类型(对于新记录自动递增,用作主键)以及用于存储客户名称的两个字段:
use testdb;
create table customers (customer_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, first_name TEXT, last_name TEXT);
3.查看新表
Show tables;
4.退出MariaDB:
Exit
(七)重置MariaDB根密码
如果您忘记了您的根MariaDB密码,则可以重置它。
1. 停止当前的MariaDB服务器实例,然后重新启动它,并选择不要求输入密码:
sudo systemctl stop mariadb
sudo mysqld_safe --skip-grant-tables&
2. 使用MariaDB根帐户重新连接到MariaDB服务器:
mysql -u root
3. 使用以下命令重置root的密码。替换password为强密码:
use mysql;
update user SET PASSWORD=PASSWORD("password") WHERE USER='root';
flush privileges;
exit
4.然后重启MariaDB
sudo systemctl start mariadb
至此,关于MariaDB就介绍到这里,如果您还有什么不明确或不懂的地方,欢迎来新世界主机咨询了解,详情请咨询Skype:vpssj.net@hotmail.com TEL:400 1109 210。我们必将竭诚为您服务。