详解Linux下通过yum安装Mariadb/MySQL数据库(腾讯云也适用)
1. 安装Mariadb
- 安装命令
yum -y install mariadb mariadb-server
- 安装完成MariaDB,首先启动MariaDB
systemctl start mariadb
- 设置开机启动
systemctl enable mariadb
MariaDB的相关简单配置
- 此命令进入到配置相关界面
mysql_secure_installation
- 首先是设置密码,会提示先输入密码
Enter current password for root (enter for none):<–初次运行直接回车
- 设置密码
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码
- 其他配置
Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车,
Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车
mariadb字符集配置(重点)
文件/etc/my.cnf配置
- 命令
vi /etc/my.cnf
此处直接给出完整的文件,自己对照[mysqld]标签下的不同
# Example MariaDB config file for very large systems.
#
# This is for a large system with memory of 1G-2G where the system runs mainly
# MariaDB.
#
# MariaDB programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, do:
# 'my_print_defaults --help' and see what is printed under
# Default options are read from the following files in the given order:
# More information at: http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /var/lib/mysql/mysql.sock# Here follows entries for some specific programs# The MySQL server
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 1M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
lower_case_table_names = 1
sql_mode=
default-storage-engine = innodb
innodb_file_per_table
max_connections = 4096
collation-server = utf8_general_ci
character-set-server = utf8# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8# Point the following paths to a dedicated disk
#tmpdir = /tmp/# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
# the syntax is:
#
# CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
# MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
# where you replace <host>, <user>, <password> by quoted strings and
# <port> by the master's port number (3306 by default).
#
# Example:
#
# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
# MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
# start replication for the first time (even unsuccessfully, for example
# if you mistyped the password in master-password and the slave fails to
# connect), the slave will create a master.info file, and any later
# change in this file to the variables' values below will be ignored and
# overridden by the content of the master.info file, unless you shutdown
# the slave server, delete master.info and restart the slaver server.
# For that reason, you may want to leave the lines below untouched
# (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id = 2
#
# The replication master for this slave - required
#master-host = <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user = <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password = <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port = <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin
#
# binary logging format - mixed recommended
#binlog_format=mixed# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /var/lib/mysql
#innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend
#innodb_log_group_home_dir = /var/lib/mysql
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 384M
#innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 100M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50[mysqldump]
quick
max_allowed_packet = 16M[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M[mysqlhotcopy]
interactive-timeout
文件/etc/my.cnf.d/client.cnf
vi /etc/my.cnf.d/client.cnf
在[client]中添加
default-character-set=utf8
文件/etc/my.cnf.d/mysql-clients.cnf
vi /etc/my.cnf.d/mysql-clients.cnf
在[mysql]中添加
default-character-set=utf8
全部配置完成,重启mariadb
systemctl restart mariadb
如果重启不成功,在日志文件里查看错误信息
cd var/log/mariadb
这个目录下有mariadb日志文件,腾讯云和本地的文件名称不一样,但都在这个目录下,自己去看
MariaDB查看字符集
show variables like "%character%"
配置好的结果如下
3、添加用户,设置权限
创建用户命令
mysql>create user username@localhost identified by 'password';
直接创建用户并授权的命令
mysql>grant all on . to username@localhost indentified by 'password';
授予外网登陆权限
mysql>grant all privileges on . to username@'%' identified by 'password';
授予权限并且可以授权
mysql>grant all privileges on . to username@'hostname' identified by 'password' with grant option;
详解Linux下通过yum安装Mariadb/MySQL数据库(腾讯云也适用)相关推荐
- linux nginx编译详解,Linux下nginx编译安装教程和编译参数详解
这篇文章主要介绍了Linux下nginx编译安装教程和编译参数详解,需要的朋友可以参考下 一.必要软件准备 1.安装pcre 为了支持rewrite功能,我们需要安装pcre 复制代码 代码如下:# ...
- linux subversion 根目录检出,经验总结:详解Linux下Subversion的安装配置记录 下
上节介绍额Linux下Subversion的安装问题,本节介绍Linux下Subversion配置问题,你可以和Windows下Subversion的安装配置做一个对比,你就会发现在这两种操作系统中S ...
- linux中which命令详解,Linux下which命令使用详解(转)
我们经常在linux要查找某个文件,但不知道放在哪里了,可以使用下面的一些命令来搜索: which 查看可执行文件的位置. whereis 查看文件的位置. locate 配合数据库查看文件位置. f ...
- 详解linux下auto工具制作Makefile源码包(制作篇)
2019独角兽企业重金招聘Python工程师标准>>> 详解linux下auto工具制作Makefile源码包(制作篇) 水木杨 一. 概述 为了更好的制作configure ...
- linux上 arm开发环境搭建,详解 LINUX下QT For ARM开发环境搭建过程
LINUX下QT For ARM开发环境搭建过程是本文介绍的内容,不多说,先来看内容.在PC上,我们需要得到两个版本的Qt,分别是:Qt-4.5.2和QtEmbedded-4.5.2-arm.前者包括 ...
- [mysql] linux下使用yum安装mysql
From: http://www.2cto.com/database/201207/141878.html linux下使用yum安装mysql 1.安装 查看有没有安装过: yum list ins ...
- Mysql —— linux下使用c语言访问mySql数据库
示例1: #include<stdio.h> #include<mysql.h> int main() { MYSQL mysql; mysql_init(&mysql ...
- CentOS7下使用yum安装MariaDB
CentOS 6 或早期的版本中提供的是 MySQL 的服务器/客户端安装包,但 CentOS 7 已使用了 MariaDB 替代了默认的 MySQL.MariaDB数据库管理系统是MySQL的一个分 ...
- linux环境下ps命令行,Linux下ps命令详解 Linux下ps命令的详细使用方法
Linux下ps命令详解 Linux上进程有5种状态:1. 运行(正在运行或在运行队列中等待) 2. 中断(休眠中, 受阻, 在等待某个条件的形成或接受到信号) 3. 不可中断(收到信号不唤醒和不可运 ...
最新文章
- python爬虫实例-Python爬虫原理与python爬虫实例大全
- java.nio.ByteBuffer中flip、rewind、clear方法的区别
- Python中乐高积木——函数
- 无法往开启kerberos的zookeeper上注册服务_笔记本WiFi信号满格,却无法上网怎么搞?...
- 解决mysql大小写敏感问题
- 20个很有帮助的 Web 前端开发教程
- tp5组装数据_tp5数据库查询和模型结合使用
- android贪吃蛇设计报告,基于android的贪吃蛇游戏设计与开发
- 实战 Flutter 象棋从零到上架
- 图解机器学习笔记-1
- 商品列表页 html 模板,商品列表模板
- Spring:Spring支持的bean作用域有哪些
- 如何下载网页php源文件,php如何实现对各种文件下载
- (JZ1619)2018.07.08【2018提高组】模拟C组 0	.音乐节拍
- 【 第一章:初识 ts】
- WiFi模块硬件兼容封装尺寸三:LGA-44/12*12mm
- 计算机考试的话语,为考试加油的暖心句子 期末考试加油鼓励的话
- 双曲铝单板是怎么生产的?
- 【推拉框-手风琴】vue3实现手风琴效果的组件
- 河南新华计算机学校学费多少,河南新华电脑学院提前三年收费 育人还是圈钱?...