mysql实用指南
mysqld --verbose --help:
可以显示 mysql 的编译配置选项,即功能配置描述。
mysql 显示所有支持的字符集: SHOW CHARACTER SET;
mysql 创建数据库或表的时候设置是否大小写敏感:
CREATE DATABASE test_database CHARACTER SET utf8 COLLATE utf8_general_cs; # 这句没什么用处,见下面的解释。 cs 意思是 case sensitive
当然你也可以在创建结束后使用alter来改变:
ALTER TABLE table_name MODIFY column_name column_datatype COLLATE utf8_general_ci; # 这句有效果, ci 意思是 case insensitive
但是,记住,mysql的database和table都是操作系统的文件系统的目录或文件名,因此不管你在创建他们时是否设置了大小写敏感,他们都是和操作系统相关的,即windows上数据库名和表名是大小写无关的,而再linux上是大小写敏感的。
只有表的column是和操作系统无关的,因为他们不是目录入口,因此你可以在创建column时设置column名是否大小写相关,也可以使用alter来修改大小写敏感否。
如果真的需要在linux下设置数据库名和table名大小写无关的话,可以考虑使用lower_case_table_names变量,但不保证有效,可以了解下:
lower_case_table_names:
https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_lower_case_table_names
If set to 0, table names are stored as specified and comparisons are case sensitive. If set to 1, table names are stored in lowercase on disk and comparisons are not case sensitive. If set to 2, table names are stored as given but compared in lowercase. This option also applies to database names and table aliases. For additional information, see Section 9.2.2, “Identifier Case Sensitivity”.
mysql 的配置文件my.cnf调用次序(mysqld --verbose --help 的输出里有以下打印):
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
Installation(完整的安装帮助参考 INSTALL-BINARY 文件):
To install and use a MySQL binary distribution, the basic command sequence looks like this:
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
指定自己的 my.cnf 配置文件:
mysqld_safe --defaults-file=FILE
若运行时找不到 libaio.so , 可以: sudo apt-get install libaio1 libaio-dev
首次启动时修改mysql的 root@'localhost' 的密码:
$ ./bin/mysql -uroot
mysql > SET PASSWORD FOR root@'localhost' = PASSWORD('your_passwd');
mysql > FLUSH PRIVILEGES;
下次登录就要: ./bin/mysql -uroot -p
修改密码:
$ mysqladmin -u root -p password newpassword
Adding User Accounts
You can create MySQL accounts two ways:
By using account-management statements intended for creating accounts and establishing their privileges, such as
CREATE USERandGRANT. These statements cause the server to make appropriate modifications to the underlying grant tables.By manipulating the MySQL grant tables directly with statements such as
INSERT,UPDATE, orDELETE.
The preferred method is to use account-management statements because they are more concise and less error-prone than manipulating the grant tables directly. All such statements are described in Section 13.7.1, “Account Management Statements”. Direct grant table manipulation is discouraged, and is not described here. The server is free to ignore rows that become malformed as a result of such modifications.
Another option for creating accounts is to use the GUI tool MySQL Workbench. Also, several third-party programs offer capabilities for MySQL account administration. phpMyAdmin is one such program.
The following examples show how to use the mysql client program to set up new accounts. These examples assume that privileges have been set up according to the defaults described in Section 2.12.4, “Securing the Initial MySQL Accounts”. This means that to make changes, you must connect to the MySQL server as the MySQL root user, which has the CREATE USER privilege.
First, use the mysql program to connect to the server as the MySQL root user:
shell> mysql --user=root mysql
If you have assigned a password to the root account, you must also supply a --password or -p option.
After connecting to the server as root, you can add new accounts. The following example uses CREATE USER and GRANT statements to set up four accounts:
mysql>CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
mysql>GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
->WITH GRANT OPTION;
mysql>CREATE USER 'monty'@'%' IDENTIFIED BY 'some_pass';
mysql>GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'
->WITH GRANT OPTION;
mysql>CREATE USER 'admin'@'localhost' IDENTIFIED BY 'admin_pass';
mysql>GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost';
mysql>CREATE USER 'dummy'@'localhost';
The accounts created by those statements have the following properties:
Two accounts have a user name of
montyand a password ofsome_pass. Both are superuser accounts with full privileges to do anything. The'monty'@'localhost'account can be used only when connecting from the local host. The'monty'@'%'account uses the'%'wildcard for the host part, so it can be used to connect from any host.The
'monty'@'localhost'account is necessary if there is an anonymous-user account forlocalhost. Without the'monty'@'localhost'account, that anonymous-user account takes precedence whenmontyconnects from the local host andmontyis treated as an anonymous user. The reason for this is that the anonymous-user account has a more specificHostcolumn value than the'monty'@'%'account and thus comes earlier in theusertable sort order. (usertable sorting is discussed in Section 6.2.4, “Access Control, Stage 1: Connection Verification”.)The
'admin'@'localhost'account has a password ofadmin_pass. This account can be used only byadminto connect from the local host. It is granted theRELOADandPROCESSadministrative privileges. These privileges enable theadminuser to execute the mysqladmin reload, mysqladmin refresh, and mysqladmin flush-xxxcommands, as well as mysqladmin processlist . No privileges are granted for accessing any databases. You could add such privileges usingGRANTstatements.The
'dummy'@'localhost'account has no password (which is insecure and not recommended). This account can be used only to connect from the local host. No privileges are granted. It is assumed that you will grant specific privileges to the account usingGRANTstatements.
To see the privileges for an account, use SHOW GRANTS:
mysql>SHOW GRANTS FOR 'admin'@'localhost';
+-----------------------------------------------------+
| Grants for admin@localhost |
+-----------------------------------------------------+
| GRANT RELOAD, PROCESS ON *.* TO 'admin'@'localhost' |
+-----------------------------------------------------+
The next examples create three accounts and grant them access to specific databases. Each of them has a user name of custom and password of obscure:
mysql>CREATE USER 'custom'@'localhost' IDENTIFIED BY 'obscure';
mysql>GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
->ON bankaccount.*
->TO 'custom'@'localhost';
mysql>CREATE USER 'custom'@'host47.example.com' IDENTIFIED BY 'obscure';
mysql>GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
->ON expenses.*
->TO 'custom'@'host47.example.com';
mysql>CREATE USER 'custom'@'%.example.com' IDENTIFIED BY 'obscure';
mysql>GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
->ON customer.*
->TO 'custom'@'%.example.com';
The three accounts can be used as follows:
The first account can access the
bankaccountdatabase, but only from the local host.The second account can access the
expensesdatabase, but only from the hosthost47.example.com.The third account can access the
customerdatabase, from any host in theexample.comdomain. This account has access from all machines in the domain due to use of the “%” wildcard character in the host part of the account name.
对于java ssh项目,一般情况下只需要添加 'monty'@'localhost' 这样的一个用户就行了,所有的远程访问都是通过他进行的,所以不需要 'monty'@'%' 这个用户。这个用户不安全。
实例:
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypass';
CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypass';
Then
GRANT ALL PRIVILEGES ON dbTest.* TO 'myuser'@'localhost';
GRANT ALL ON *.* TO 'myuser'@'localhost';
GRANT ALL ON *.* TO 'myuser'@'%';
mysql实用指南的更多相关文章
- Chrome 控制台实用指南【转】
转自伯乐在线. Chrome 控制台实用指南 前言 Chrome浏览器我想是每一个前端er必用工具之一吧,一部分原因是它速度快,体积不大,支持的新特性也比其它浏览器多,还有一部分我想就是因为它的控制台 ...
- A Practical Guide to Distributed Scrum - 分布式Scrum的实用指南 - 读书笔记
最近读了这本IBM出的<A Practical Guide to Distributed Scrum>(分布式Scrum的实用指南),书中的章节结构比较清楚,是针对Scrum项目进行,一个 ...
- MSIL实用指南-生成索引器
MSIL实用指南-生成索引器 索引器是一种特殊的属性,它有参数的,也有get和set方法,属性名称一般是"Item",并且方法名称一般名称是"get_Item" ...
- MySql权威指南
[MySql权威指南] 1.索引(index):原始数据纪录的排序情况. 2.存储过程(store procedure),就是函数. 3.触发器是一组SQL命令,当数据库执行特定操作时触发,如UPDA ...
- webdriver实用指南python版本(1)-安装开发环境
webdriver实用指南是本人编写的系列丛书,包括ruby版.python版和java版.在线版是免费的,之前是放在我的github上,但是很多同学总不记得地址,现在转到我的博客上,方便大家阅读. ...
- 乙醇的webdriver实用指南ruby版本
webdriver实用指南是乙醇2013年分享计划的一部分,作为对已逝去的selenium2时代的追忆. 目录如下 启动浏览器 关闭浏览器 浏览器最大化 设置浏览器大小 访问链接 打印当前页面的tit ...
- [转载]Firefox插件(plugins)开发实用指南
转自: http://huandu.me/2010/02/11/595/ Firefox插件可实现强大功能,但其中麻烦事情不少.写这个实用指南首先是为了方便自己记忆,免得以后再次栽倒一些坑里面,如果能 ...
- 《Android Studio实用指南》7.1 AndroidStudio代码检查工具概述
本文节选自<Android Studio实用指南> 作者: 毕小朋 目前本书已上传到百度阅读, 在百度中搜索[Anroid Studio实用指南]便可以找到本书. Android Stud ...
- 《Android Studio实用指南》4.27 使用演示模式
本文节选自<Android Studio实用指南> 第4章第27节 作者: 毕小朋 目前本书已上传到百度阅读, 在百度中搜索[Anroid Studio实用指南]便可以找到本书. 什么是演 ...
随机推荐
- MVC-Model数据注解(二)-自定义
由于系统的数据注解肯定不适合所有的场合,所以有时候我们需要自定义数据注解. 自定义数据注解有两种,一种是直接写在模型对象中,这样做的好处是验证时只需要关心一种模型对象的验证逻辑,缺点也 ...
- 一步步学习ASP.NET MVC3 (12)——FileResult
请注明转载地址:http://www.cnblogs.com/arhat 忙了两天,本来老魏昨天就应该写出新的文章,但是由于昨天雨夹雪而且加上昨天晚上加了班,到家都没饭吃了,一看时间都9点了,什么饭店 ...
- python 时间及日期函数
本人最近新学python ,用到关于时间和日期的函数,经过一番研究,从网上查找资料,经过测试,总结了一下相关的方法. import timeimport datetime '''时间转化为时间戳: 2 ...
- Automotive Security的一些资料和心得(8):Hardware Security Module (HSM)
1. Introduction - 保护软件的安全性措施,作为值得信赖的安全锚,- 安全地生成,存储和处理安全性关键材料屏蔽任何潜在的恶意软件,?- 通过运用有效的限制硬件篡改攻击的可能性篡改保护措施 ...
- About Interface
http://www.codeproject.com/Articles/18743/Interfaces-in-C-For-Beginners Interface can't have thi ...
- 升级mac中的系统之后,给PHP安装扩展常出现问题
(1)在装mcrypt插件时报错,提示:mcrypt fatal error: 'php.h' file not found,然后又仔细操作了一次在输完phpize回车时就已经开始出错了,出错信息如下 ...
- javascript-代码复用模式
代码复用模式 1)使用原型继承 函数对象中自身声明的方法和属性与prototype声名的对象有什么不同: 自身声明的方法和属性是静态的, 也就是说你在声明后,试图再去增 ...
- 安装Ubuntu 14.04后要做的5件事情
转自安装Ubuntu 14.04后要做的5件事情 Ubuntu目前是世界上最流行的Linux操作系统,它提供了桌面版本和服务器版本,其他流行的Linux发行版本如Linux Mint也是基于Ubunt ...
- Qt中QString,int,char,QByteArray之间相互转换
http://blog.csdn.net/ymc0329/article/details/7284514 int 转 QString int m=1; QString b; b=QString::n ...
- float 和 real
用于表示浮点数值数据的大致数值数据类型.浮点数据为近似值:因此,并非数据类型范围内的所有值都能精确地表示. 注意: real 的 SQL-92 同义词为 float(24). 数据类型 范围 存储 ...