在Ubuntu 16.04(Xenial Xerus)LTS上安装MariaDB 10.5
时间:2020-02-23 14:40:54 来源:igfitidea点击:
这篇文章将指导我们完成在代码名为Xenial的Ubuntu 16.04 LTS上安装MariaDB 10.5. MariaDB是最流行的开源关系数据库管理系统之一。
由于担心被甲骨文收购,MariaDB是MySQL的社区开发分支。它打算在GNU GPL下保持免费。 MariaDB的开发由MySQL的某些原始开发人员领导。
在Ubuntu 16.04 LTS上安装MariaDB 10.5
要在Ubuntu 16.04上安装MariaDB 10.5,需要将MariaDB存储库添加到系统上。
sudo apt update
运行以下命令以导入MariaDB存储库PGP密钥并添加存储库。
sudo apt -y install software-properties-common gnupg-curl sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc' sudo add-apt-repository 'deb [arch=amd64,arm64,i386,ppc64el] http://mariadb.mirror.liquidtelecom.com/repo/10.5/ubuntu xenial main'
更新系统软件包列表并安装MariaDB:
sudo apt update sudo apt install mariadb-server mariadb-client
使用y键接受安装
... Reading state information... Done The following additional packages will be installed: galera-4 gawk libaio1 libdbi-perl libgdbm3 libmariadb3 libmpfr4 libpcre2-8-0 libperl5.22 libsigsegv2 lsof mariadb-client-10.5 mariadb-client-core-10.5 mariadb-common mariadb-server-10.5 mariadb-server-core-10.5 mysql-common perl perl-modules-5.22 psmisc rsync socat Suggested packages: gawk-doc libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl mailx mariadb-test tinyca perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl make Recommended packages: libdbd-mariadb-perl | libdbd-mysql-perl libterm-readkey-perl libhtml-template-perl rename The following NEW packages will be installed: galera-4 gawk libaio1 libdbi-perl libgdbm3 libmariadb3 libmpfr4 libpcre2-8-0 libperl5.22 libsigsegv2 lsof mariadb-client mariadb-client-10.5 mariadb-client-core-10.5 mariadb-common mariadb-server mariadb-server-10.5 mariadb-server-core-10.5 mysql-common perl perl-modules-5.22 psmisc rsync socat 0 upgraded, 24 newly installed, 0 to remove and 2 not upgraded. Need to get 30.8 MB of archives. After this operation, 241 MB of additional disk space will be used. Do you want to continue? [Y/n] y
通过设置root密码,禁用远程root登录和删除测试数据库来保护数据库安装:
$sudo 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 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] 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!
尝试不带密码访问mariadb shell
$mysql -u root <ENTER>
我们应该收到拒绝访问错误,这意味着我们需要提供密码:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
通过提供root密码进行相同的操作:
$mysql -u root -p Enter password: <ENTER-PASSWORD> Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 14 Server version: 10.5.4-MariaDB-1:10.5.4+maria~xenial mariadb.org binary distribution Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> SELECT version(); +----------------------------------------+ | version() | +----------------------------------------+ | 10.5.4-MariaDB-1:10.5.4+maria~xenial | +----------------------------------------+ 1 row in set (0.001 sec)
创建一个测试数据库
MariaDB [(none)]> CREATE DATABASE test_db; Query OK, 1 row affected (0.001 sec) MariaDB [(none)]> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test_db | +--------------------+ 4 rows in set (0.002 sec) MariaDB [(none)]> DROP DATABASE test_db; Query OK, 0 rows affected, 2 warnings (0.002 sec) MariaDB [(none)]> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.001 sec) MariaDB [(none)]> \q Bye
安装桌面数据库管理工具
如果我们不喜欢使用MySQL命令行,请考虑安装数据库工具来为我们提供帮助。请查看下面的教程:
在Ubuntu上安装和配置DBeaver