Mysql学习笔记(一):MariaDB在CentOS7.8上的安装、远程登录授权

前段时间买了台 云服务想着不用在本地开虚拟机,这样对自己的笔记本来说是个解脱。然后就准备在上面装个MariaDB,虽然网上教程一大堆,但是知识只有掌握在自己手里才算是真的掌握了。为了加深印象,所以我准备从新装一次,以下是操作过程,记录一下。

1.首先查看是否安装了MariaDB


 
 
  1. [root@VM-0-16-centos ~] # rpm -qa|grep mariadb
  2. mariadb-5.5.68-1.el7.x86_64
  3. mariadb-server-5.5.68-1.el7.x86_64
  4. mariadb-libs-5.5.68-1.el7.x86_64
  5. [root@VM-0-16-centos ~] #

2.卸载MariaDB


 
 
  1. [root@VM-0-16-centos ~] # yum remove mariadb
  2. ······
  3. Removed:
  4. mariadb.x86_64 1:5.5.68-1.el7
  5. Dependency Removed:
  6. mariadb-server.x86_64 1:5.5.68-1.el7
  7. Complete!
  8. [root@VM-0-16-centos ~] #

3.删除遗留目录


 
 
  1. [root@VM-0-16-centos ~] # ll /etc/my.cnf
  2. -rw-r--r-- 1 root root 753 Dec 21 15:12 /etc/my.cnf
  3. [root@VM-0-16-centos ~] # ll /var/lib/mysql/
  4. total 28700
  5. -rw-rw---- 1 mysql mysql 16384 Dec 22 10:42 aria_log.00000001
  6. -rw-rw---- 1 mysql mysql 52 Dec 22 10:42 aria_log_control
  7. -rw-rw---- 1 mysql mysql 18874368 Dec 22 10:42 ibdata1
  8. -rw-rw---- 1 mysql mysql 5242880 Dec 22 10:42 ib_logfile0
  9. -rw-rw---- 1 mysql mysql 5242880 Dec 21 14:59 ib_logfile1
  10. drwx------ 2 mysql mysql 4096 Dec 21 14:59 mysql
  11. drwx------ 2 mysql mysql 4096 Dec 21 14:59 performance_schema
  12. [root@VM-0-16-centos ~] # rm -rf /etc/my.cnf /var/lib/mysql
  13. [root@VM-0-16-centos ~] #

4.重新安装


 
 
  1. [root @VM- 0- 16-centos ~] # yum -y install mariadb mariadb-server #安装mariadb
  2. [root @VM- 0- 16-centos ~] # systemctl start mariadb #启动mariadb
  3. [root @VM- 0- 16-centos ~] # systemctl enable mariadb #开机启动mariadb

5.配置mariadb


 
 
  1. [root@VM-0-16-centos ~] # mysql_secure_installation #配置mariadb
  2. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
  3. SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
  4. In order to log into MariaDB to secure it, we 'll need the current
  5. password for the root user. If you've just installed MariaDB, and
  6. you haven 't set the root password yet, the password will be blank,
  7. so you should just press enter here.
  8. Enter current password for root (enter for none): <–初次运行直接回车
  9. OK, successfully used password, moving on...
  10. Setting the root password ensures that nobody can log into the MariaDB
  11. root user without the proper authorisation.
  12. Set root password? [Y/n] y #是否设置root用户密码,输入y并回车
  13. New password: #输入root用户密码
  14. Re-enter new password: #再输入一次root用户密码
  15. Password updated successfully!
  16. Reloading privilege tables..
  17. ... Success!
  18. By default, a MariaDB installation has an anonymous user, allowing anyone
  19. to log into MariaDB without having to have a user account created for
  20. them. This is intended only for testing, and to make the installation
  21. go a bit smoother. You should remove them before moving into a
  22. production environment.
  23. Remove anonymous users? [Y/n] y #是否删除匿名用户,生产环境建议删除,所以直接回车
  24. ... Success!
  25. Normally, root should only be allowed to connect from 'localhost '. This
  26. ensures that someone cannot guess at the root password from the network.
  27. Disallow root login remotely? [Y/n] n #是否禁止root远程登录,根据自己的需求选择y/n并回车
  28. ... skipping.
  29. By default, MariaDB comes with a database named ' test ' that anyone can
  30. access. This is also intended only for testing, and should be removed
  31. before moving into a production environment.
  32. Remove test database and access to it? [Y/n] y #是否删除test数据库
  33. - Dropping test database...
  34. ... Success!
  35. - Removing privileges on test database...
  36. ... Success!
  37. Reloading the privilege tables will ensure that all changes made so far
  38. will take effect immediately.
  39. Reload privilege tables now? [Y/n] y #重新加载权限表
  40. ... Success!
  41. Cleaning up...
  42. All done! If you've completed all of the above steps, your MariaDB
  43. installation should now be secure.
  44. Thanks for using MariaDB!
  45. [root@VM-0-16-centos ~] #

6.新增新用户及数据库


 
 
  1. [root@VM-0-16-centos ~] # mysql -uroot -p
  2. Enter password:
  3. Welcome to the MariaDB monitor. Commands end with ; or \g.
  4. Your MariaDB connection id is 13
  5. Server version: 5.5.68-MariaDB MariaDB Server
  6. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  7. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  8. MariaDB [(none)]> create user eric@ '%' identified by 'eric'; #新建用户,%代表任意ip都可以登录
  9. Query OK, 0 rows affected (0.00 sec)
  10. MariaDB [(none)]> create database ericdb; #创建数据库
  11. MariaDB [(none)]> grant all privileges on ericdb.* to eric@ '%' ; #为eric用户授予ericdb的所有权限
  12. Query OK, 0 rows affected (0.00 sec)

接下来就可以使用eric用户在ericdb里做操作啦,以上。

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
在CentOS 7上安装MariaDB之后,如果你想继续安装MySQL,你需要进行一些额外的步骤。安装MySQL的过程与安装MariaDB略有不同。以下是在CentOS 7上安装MySQL的一般步骤: 1. 首先,确保你已经卸载了之前安装MariaDB。你可以使用如下命令卸载MariaDB: ``` sudo yum remove mariadb-libs ``` 2. 安装MySQL的依赖包。在终端中运行以下命令: ``` sudo yum install -y https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm ``` 3. 安装MySQL服务器。运行以下命令: ``` sudo yum install -y mysql-server ``` 4. 启动MySQL服务并设置开机自启动: ``` sudo systemctl start mysqld sudo systemctl enable mysqld ``` 5. 运行MySQL安全脚本,该脚本将帮助你设置MySQL的root密码等安全选项: ``` sudo mysql_secure_installation ``` 6. 完成安全脚本的设置后,你可以通过以下命令登录到MySQL: ``` mysql -u root -p ``` 请注意,在安装过程中可能还会有其他附加步骤和设置。具体步骤可能会根据你的系统配置和需求而有所不同。确保按照MySQL官方文档或适用于CentOS 7的特定指南进行操作。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [CentOS 7 安装mariadb](https://blog.csdn.net/xueren_83/article/details/124325803)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [centos 7安装mysql5.5和安装 mariadb使用的命令](https://download.csdn.net/download/weixin_38606019/12830336)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值