MySQL初始化与用户配置
数据库初始化
默认情况下,数据已经初始化好,数据可参见默认配置文件/etc/my.cnf
在其他位置重新初始化MySQL数据库:
basedir是mysql的安装根目录,ldata是数据初始化的目录
mysql_install_db --basedir=/ --ldata=./data
相关提示:
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands: mysqladmin -u root password 'new-password'
mysqladmin -u root -h xxx.xxx.xxx.xxx password 'new-password' Alternatively you can run: mysql_secure_installation which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd . ; mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com WARNING: Found existing config file /etc/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /etc/my-new.cnf,
please compare it with your file and take the changes you need. WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
数据库实例配置
my.cnf配置文件内容
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html [mysqld] # Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at % of total RAM for dedicated server, else %.
# innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin log-error=/<your_dir>/log/mysql.log.err
general_log = ON
general_log_file=/<your_dir>/log/mysql_general.log
slow_query_log = ON
long_query_time=
slow_query_log_file = /<your_dir>/log/mysql_slow_query.log # These are commonly set, remove the # and set as required.
# basedir = .....
datadir=/<your_dir>/data
port =
# server_id = .....
socket = /<your_dir>/mysql..sock
pid-file =/<your_dir>/mysql..pid # Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
user=mysql
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
数据库启动
mysqld_safe --defaults-file=/<your_dir>/my.cnf
数据库登录
mysql --socket=mysql.3306.sock
数据库实例管理
查看数据库状态
mysqladmin --socket=mysql.3306.sock status
更改root密码:
mysqladmin -u root password root --socket=mysql.3306.sock
数据库关闭
mysqladmin -proot -uroot --socket=mysql.3306.sock shutdown
用户和权限管理
名为mysql的数据库中存放这元数据,其中use表与用户和权限有关。
use表的Host User Password列与用户登录有关,这三列可以确定登录用户的身份。
use表的Select_priv、Insert_priv等以priv结尾的列与用户权限有关,Y表示对所有表生效,N表示不对所有表生效。
使用数据库root用户登录数据库,并使用mysql数据库
mysql -uroot -proot --socket=mysql.3306.sock -D mysql
新建普通用户
create user 'username'@'host' identified by 'password'
其中host可以由%代替,表示对所有host登录的都适用。
或者
INSERT INTO mysql.user(Host,User,Password,ssl_cipher,x509_issuer,x509_subject) VALUES('%','username',PASSWORD('password'),'','','');
FLUSH PRIVILEGES
或者
GRANT SELECT ON *.* TO 'username'@'%' identified by 'password';
其中*.*表示对所有数据库的所有表,这条语句可以在创建用户的同时给权限。
用户权限
查看权限
SHOW GRANT
赋予权限
GRANT SELECT,UPDATE,DELETE ON *.* TO 'username'@'%'
收回权限
REVOKE ALL ON *.* TO 'username'@'%'
FLUSH PRIVILEGES
删除用户
DROP USER 'username'@'%'
或者
DELETE FROM mysql.user WHERE Host = '%' AND User = 'username'
修改密码
使用命令mysqladmin -u -username -p password "new_password"
或者改表
UPDATE user SET Password = PASSWORD('new_password') WHERE USER = 'username' and Host = '%'
FLUSH PRIVILEGES
或者修改当前用户密码
SET PASSWORD = PASSWORD("new_password");
修改其他用户密码
SET PASSWORD FOR 'username'@'%'=PASSWORD("new_password")
发布地址:www.cnblogs.com/qiusuo/p/9451717.html
MySQL初始化与用户配置的更多相关文章
- P1-Linux下安装MySQL及登录用户配置
Linux下安装MySQL及登录用户配置 环境:Centos7.4 Mysql5.6 1. 查询是否安装 MySQL和MariaDB rpm -qa | grep -i mysql rpm -q ...
- CentOS下配置MySQL允许root用户远程登录
1.常用命令: 安装上传下载文件命令yum install lrzsz安装webget工具yum -y install wget ----------------------------------- ...
- 33.Docker安装Mysql及用户配置
mysql在官方上有两个镜像 这个是一个优化过的mysql 使用这个命令 安装mysql 演示最简单的方式去安装mysql: 这种方式安装的用户名没有,密码没有 docker run -d -p 33 ...
- MySQL高级学习笔记(二):mysql配置文件、mysql的用户与权限管理、mysql的一些杂项配置
文章目录 mysql配置文件 二进制日志log-bin 错误日志log-error 数据文件 两系统 Myisam存放方式 innodb存放方式 如何配置 mysql的用户与权限管理 MySQL的用户 ...
- 实现FTP+PAM+MySQL环境,批量配置虚拟用户
实现FTP+PAM+MySQL环境,批量配置虚拟用户 搭建环境: CentOS6.5或CentOS6.7 [root@vhost3 ~]# uname -a Linux vhost3 2.6.32-5 ...
- CentOS系统MySQL双机热备配置
1 概述 在集成项目中需要应对不同环境下的安装配置,主流操作系统大致可以分为三种:Linux.Windows以及UNIX.其中Linux备受青睐的主要原因有两个: 首先,Linux作为自由软件有两个 ...
- mysql多实例的配置和管理
原文地址:mysql多实例的配置和管理 作者:飞鸿无痕 多实例mysql的安装和管理 mysql的多实例有两种方式可以实现,两种方式各有利弊.第一种是使用多个配置文件启动不同的进程来实现多实例,这种方 ...
- CentOs中mysql的安装与配置
在linux中安装数据库首选MySQL,Mysql数据库的第一个版本就是发行在Linux系统上,其他选择还可以有postgreSQL,oracle等 在Linux上安装mysql数据库,我们可以去其官 ...
- LNMP(linux+nginx+mysql+php)服务器环境配置
一.简介 Nginx是俄罗斯人编写的十分轻量级的HTTP服务器,Nginx,它的发音为 “engine X”, 是一个高性能的HTTP和反向代理服务器,同时也是一个IMAP/POP3/SMTP 代理服 ...
随机推荐
- Params应用
有时候我们要想传递可变数量的参数改怎么办??Params给我们提供了一个很好的方法 Parmas: 1.只运用方法的最后一位参数 2.这个参数只能标志任意类型的一位数组 3.添加了params这个参数 ...
- Unity热更新技术整理
一.热更新学习介绍 1.什么是热更新 举例来说: 游戏上线后,玩家下载第一个版本(70M左右或者更大),在运营的过程中,如果需要更换UI显示,或者修改游戏的逻辑,这个时候,如果不使用热更新,就需要重新 ...
- 浅谈https\ssl\数字证书
全球可信的SSL数字证书申请:http://www.shuzizhengshu.com 在互联网安全通信方式上,目前用的最多的就是https配合ssl和数字证书来保证传输和认证安全了.本文追本溯源围绕 ...
- linux 文件系统基本结构
1.Linux文件系统为一个倒转的单根树状结构 2.文件系统的根为"/" 3.文件系统严格区分大小写 4.路径使用"/",与Windows使用"\&q ...
- Transaction And Lock--由外键导致的死锁
死锁发生情况:1. 存在表A和表B,表A的主键是表B的外键2.事务A在表A上申请到X锁以修改表A中数据和删除表A中的数据,然后需要检查表B中的数据是否满足外键约束,从而需要Range锁来锁住表B3.事 ...
- [Maven实战-许晓斌]-[第三章] Mave使用入门二(在IDE中的使用) [第四章] 案例的背景介绍
创建maven项目
- 洛谷P4097 [HEOI2013]Segment(李超线段树)
题面 传送门 题解 调得咱自闭了-- 不难发现这就是个李超线段树,不过因为这里加入的是线段而不是直线,所以得把线段在线段树上对应区间内拆开之后再执行李超线段树的操作,那么复杂度就是\(O(n\log^ ...
- python基础,变量,if语句
一.python初识 python是一门 解释型弱类型编程语言. 特点: 简单.明确.优雅 二.python的解释器 CPython. 官方提供的. 内部使用c语言来实现 PyPy. 一次性把我们的 ...
- loj2497 [PA2017]Banany(动态淀粉质)
link 给定一棵树,点有点权,边有边权,你每次修改一个点点权或者是修改一个边边权 你一开始在1号点,你每次改节点之后你需要移动到另一个节点,满足这个节点权值减去路径长度最大(下一次从这个节点移动)如 ...
- ajax跨域请求问题
ajax是不允许跨域请求的,今天在使用bootstap-table的时候,data-url使用的地址是绝对地址,而非相对地址,因此在载入数据的时候就出错了. 启动的时候使用是 http://127.0 ...