文章目录

  • 安装MariaDB
  • 设置密码
  • 修改端口
  • 允许远程访问

安装MariaDB

MariaDB存在apt 的更新中,如果追求最新版,可以下载二进制文件进行编译安装,但普通人用没必要那么麻烦,直接装就行了。

apt update && apt install mariadb-server mariadb-client

查看数据库情况:

-> # systemctl status mariadb
● mariadb.service - MariaDB 10.1.38 database serverLoaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)Active: active (running) since Fri 2019-03-29 10:03:39 CST; 1min 13s agoDocs: man:mysqld(8)https://mariadb.com/kb/en/library/systemd/Main PID: 30065 (mysqld)Status: "Taking your SQL requests now..."Tasks: 27 (limit: 1055)CGroup: /system.slice/mariadb.service└─30065 /usr/sbin/mysqldMar 29 10:03:43 ubuntu /etc/mysql/debian-start[30112]: Processing databases
Mar 29 10:03:43 ubuntu /etc/mysql/debian-start[30112]: information_schema
Mar 29 10:03:43 ubuntu /etc/mysql/debian-start[30112]: mysql
Mar 29 10:03:43 ubuntu /etc/mysql/debian-start[30112]: performance_schema
Mar 29 10:03:43 ubuntu /etc/mysql/debian-start[30112]: Phase 6/7: Checking and upgrading tables
Mar 29 10:03:43 ubuntu /etc/mysql/debian-start[30112]: Processing databases
Mar 29 10:03:43 ubuntu /etc/mysql/debian-start[30112]: information_schema
Mar 29 10:03:43 ubuntu /etc/mysql/debian-start[30112]: performance_schema
Mar 29 10:03:43 ubuntu /etc/mysql/debian-start[30112]: Phase 7/7: Running 'FLUSH PRIVILEGES'
Mar 29 10:03:43 ubuntu /etc/mysql/debian-start[30112]: OK

设置密码

运行如下命名进行密码设置:

mysql_secure_installation

示例如下:

-> # mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS 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.
#设置root密码
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.
#是否允许root用户原创登录
Disallow root login remotely? [Y/n] n... skipping.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!

进行连接测试:

mysql -u root -p

输入密码后连接即可成功

修改端口

nano /etc/mysql/mariadb.conf.d/50-server.cnf

修改如下:

[mysqld]#
# * Basic Settings
#
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 51009
#修改端口为一个随机端口号
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 0.0.0.0
#bind-address改为0.0.0.0,从而可以外网访问

注意:MariaDB 在Debian 上的默认字符集是utf8mb4,可以直接使用中文


#
# * Character sets
#
# MySQL/MariaDB default is Latin1, but in Debian we rather default to the full
# utf8 4-byte character set. See also client.cnf
#
character-set-server  = utf8mb4
collation-server      = utf8mb4_general_ci

重启mariadb:

systemctl restart mysql

进行测试:

mysql -h localhost -P 51009 -u root -p

允许远程访问

连接mariadb,添加root的远程访问权限

-> # mysql -h localhost -P 51009 -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 30
Server version: 10.1.38-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04Copyright (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)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
MariaDB [mysql]> select user,host,password from user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *1945EC0A6D14A304922B91B7F14585A0B75D12 |
+------+-----------+-------------------------------------------+
1 row in set (0.02 sec)
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'etrvrvsfse56uh' WITH GRANT OPTION;
Query OK, 0 rows affected (0.23 sec)MariaDB [mysql]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)MariaDB [mysql]> select user,host,password from user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *194500000000ECA6D000000000000585AB7E5D12 |
| root | %         | *2470C0C06DEE41618BB00000000000000EC9DE19 |
+------+-----------+-------------------------------------------+
2 rows in set (0.04 sec)

然后就可以用授权的密码远程访问了。

debian,ubuntu下安装MariaDB,并设置密码,修改端口,允许外网访问相关推荐

  1. Linux :debian(ubuntu)下安装和使用haskell

    文章目录 Linux :debian(ubuntu)下安装haskell 安装 使用 Linux :debian(ubuntu)下安装haskell 安装 直接使用apt进行安装: sudo apt- ...

  2. Linux: debian/ubuntu下安装和使用Java 11

    Linux: debian/ubuntu下安装和使用Java 11 只需6行命令: su - echo "deb http://ppa.launchpad.net/linuxuprising ...

  3. Linux: debian/ubuntu下安装和使用Java 8

    Linux: debian/ubuntu下安装和使用Java 8 7行命令解决问题: su - echo "deb http://ppa.launchpad.net/webupd8team/ ...

  4. Linux: debian/ubuntu下安装Neo4j

    文章目录 Linux: debian/ubuntu下安装Neo4j Linux: debian/ubuntu下安装Neo4j Neo4j的官方仓库地址:neo4j/neo4j: Graphs for ...

  5. 安装宝塔面板并建立网络使用外网访问

    安装宝塔面板与外网连接 安装宝塔面板 安装完毕后是这样的 输入宝塔账号才能使用 默认安装以下软件 修改账号密码及安全入口 注意事项80端口不能外网登录 安装宝塔面板 使用命令:wget -O inst ...

  6. Debian/Ubuntu下安装Apache的Mod_Rewrite模块的步骤分享

    启用 Mod_rewrite 模块: sudo a2enmod rewrite 另外,也可以通过将 /etc/apache2/mods-available/rewrite.load 连接到 /etc/ ...

  7. debian/ubuntu下安装java8

    2019独角兽企业重金招聘Python工程师标准>>> 通过oracle-java8-installer 安装的 方法: http://blog.csdn.net/feelang/a ...

  8. debian,ubuntu 安装mongodb 允许外网访问,修改端口,设置用户和密码

    使用apt安装mongodb: apt update && apt install mongodb 查看运行状态: systemctl status mongodb.service 结 ...

  9. ubuntu, debian 安装redis,设置开机自动启动和密码,允许外网访问

    文章目录 ubuntu, debian 安装redis,设置开机自动启动和密码,允许外网访问 通过Python3连接redis ubuntu, debian 安装redis,设置开机自动启动和密码,允 ...

最新文章

  1. AlarmManager与PendingIntent的联合使用(二)
  2. Tensorflow LSTM时间序列预测的尝试
  3. sqlserver2008r2修改表不能保存的解决方法
  4. css3技巧——产品列表之鼠标滑过效果(一)
  5. 搭建国产化统信UOS操作系统虚拟机
  6. 有些CAD通过Arcgis程序读取后,发现面积不对
  7. 5-1MongoDB 实验——数据备份和恢复--edu上面的nosql题目
  8. Java修炼——手写服务器项目
  9. 【学习笔记】树莓派(3B+)及VMware对于代理Proxy的使用
  10. 车载网络测试 - UDS诊断篇 - 故障码(DTC)
  11. nginx监听80端口转发到tomcat 8080端口
  12. java编译方法参数(-parameters)名为arg0问题
  13. DPDK:UDP 协议栈的实现
  14. discuz db_mysql.calss.php_刚发现得好东西!discuz 7.0 db_mysql.php 详解
  15. mybatis-plus无spring框架
  16. ACC——carsim与simulink联合仿真
  17. VSC C++ 配置
  18. 【大唐杯备考】——5G基站开通与调测(学习笔记)
  19. 国潮文化引领手办市场新风向 b站会员购成消费首选平台
  20. 手把手教你用Python脚本调用 DeepL API Pro 进电子书的行进行中英文自动翻译

热门文章

  1. 其他算法-SVD奇异值分解
  2. Amber计算MM能量
  3. 杀死某个已知名字的进程
  4. R语言与数据分析(10)-内置数据集
  5. NAR:查询未培养病毒基因组的综合生态和进化框架IMG/VR v3
  6. Nature:拟南芥根系微生物组的结构
  7. 扩增子分析神器USEARCH简介
  8. 文档计算机无法分页,同一EXCEL文件在不同计算机上显示分页不同解决办法(6页)-原创力文档...
  9. pandas使用groupby函数和count函数返回的是分组下每一列的统计值(不统计NaN缺失值)、如果多于一列返回dataframe、size函数返回分组下的行数结果为Series(缺失值不敏感)
  10. R语言构建xgboost模型:xgb.cv函数交叉验证确定模型的最优子树个数(可视化交叉验证对数损失函数与xgboost模型子树个数的关系)、交叉验证获取最优子树之后构建最优xgboost模型