首页
编程随笔
Java笔记
Html/Css/Js
Android
后端笔记
服务器搭建
BUG收集
Java异常
Android异常
在线工具
Json格式化
编码/解码
Epub在线编辑
登录
发布文章
个人文章
退出登录
首页
技术教程
BUG收集
在线工具
资源下载
登录
发布文章
退出登录
搜索
当前位置:
首页
-
博客
- 正文
关闭
centos安装Mariadb数据库
更新时间:2021-03-21 18:48:41
阅读数:894
发布者:落幕
###1、创建mariadb.repo mariadb.repo获取地址 http://downloads.mariadb.org/mariadb/repositories/ ![sdf](https://tv.speechb.com/blog/mariadb_rep.png "fsd") >vim /etc/yum.repos.d/mariadb.repo 复制下面文本 # MariaDB 10.5 CentOS repository list - created 2021-03-21 10:30 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.5/centos8-amd64 module_hotfixes=1 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 ###2、 yum安装 >yum install MariaDB-server MariaDB-client ###3、 配置 1)安装完成MariaDB,首先启动MariaDB,两条命令都可以 >systemctl start mariadb 2)设置开机启动 >systemctl enable mariadb 3)简单配置(最新mariadb已经失效,直接使用mysql -u root即可登录) >mysql_secure_installation 输入root(mysql)的密码。默认没有,直接回车 Enter current password for root (enter for none): 是否切换到unix套接字身份验证[Y/n] Switch to unix_socket authentication [Y/n] n 是否设置root密码 Change the root password? [Y/n] 如果选Y,就输入2次密码 New password: Re-enter new password: 是否删除匿名用户?(就是空用户),建议删除 Remove anonymous users? [Y/n] 是否不允许远程root登录 Disallow root login remotely? [Y/n] 是否删除test数据库 Remove test database and access to it? [Y/n] 是否重新加载权限表,回车 Reload privilege tables now? [Y/n] 初始化MariaDB完成,接下来测试登录 mysql -uroot -p [回车,之后输入密码] 4)配置字符utf-8编码 设置客户端: vim /etc/my.cnf.d/mysql-clients.cnf [mysql] default-character-set=utf8 设置服务端: vim /etc/my.cnf.d/server.cnf [mysqld] init_connect='SET collation_connection = utf8_general_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_general_ci skip-character-set-client-handshake #开启慢查询 slow_query_log = ON slow_query_log_file = /usr/local/mysql/data/slow.log long_query_time = 1 全部配置完成,重启mariadb >systemctl restart mariadb 之后进入MariaDB查看字符集 mysql> show variables like "%character%";show variables like "%collation%"; 显示为 MariaDB [(none)]> show variables like "%character%"; MariaDB [(none)]> show variables like "%collation%"; +--------------------------+----------------------------+ | 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/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec) +----------------------+-----------------+ | Variable_name | Value | +----------------------+-----------------+ | collation_connection | utf8_general_ci | | collation_database | utf8_general_ci | | collation_server | utf8_general_ci | +----------------------+-----------------+ 3 rows in set (0.00 sec) 字符集配置完成。 ###4、添加用户,设置权限 1)创建用户命令 mysql>create user username@localhost identified by 'password'; 2)直接创建用户并授权的命令 mysql>grant all on *.* to username@localhost indentified by 'password'; 3)授予外网登陆权限,但不能二级授权; mysql>grant all privileges on *.* to username@'%' identified by 'password'; 4)授予权限并且可以二次授权 mysql>grant all privileges on *.* to username@'hostname' identified by 'password' with grant option; 简单的用户和权限配置基本就这样了。 其中只授予部分权限把 其中 all privileges或者all改为: select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file 5)允许root远程登录 MariaDB [(none)]>use mysql; MariaDB [mysql]>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456'; 这里的123456为你给新增权限用户设置的密码,%代表所有主机,也可以具体到#你的主机ip地址 MariaDB [mysql]>flush privileges; 这句表示从mysql数据库的grant表中重新加载权限数据因为MySQL把权限都放在了cache中,所以在做完更改后需要重新加载。 localhost不用密码也能登录,设置密码即可: alter user 'root'@'localhost' identified by '123'; ###5、更改数据库端口 mysql更改端口 Vi /etc/my.cnf [msyqld] port=
systemctl restart mysqld