[转]MySQL基本命令 一、mysql服务操作 0、查看数据库版本 sql- status; 1、net start mysql //启动mysql服务 2、net stop mysql //停止mysql服务 3、mysql -h主机地址 -u用户名 -p用户密码 //进入mysql数据库 4、quit //退出mysql操作 5、mysqladmin -u用户
[转]MySQL基本命令一、mysql服务操作
0、查看数据库版本 sql-> status;
1、net start mysql //启动mysql服务
2、net stop mysql //停止mysql服务
3、mysql -h主机地址 -u用户名 -p用户密码 //进入mysql数据库
4、quit //退出mysql操作
5、mysqladmin -u用户名 -p旧密码 password 新密码 //更改密码
6、grant select on 数据库.* to 用户名@登录主机 identified by "密码" //增加新用户
exemple:
例 2、增加一个用户test2密码为abc,让他只可以在localhost上登录,并可以对数据库mydb进行查询、插入、修改、删除的操作 (localhost指本地主机,即MYSQL数据库所在的那台主机),这样用户即使用知道test2的密码,他也无法从internet上直接访问数据 库,只能通过MYSQL主机上的web页来访问了。
grant select,insert,update,delete on mydb.* to test2@localhost identified by "abc";
如果你不想test2有密码,可以再打一个命令将密码消掉。
grant select,insert,update,delete on mydb.* to test2@localhost identified by "";
二、数据库操作
1、show databases; //列出数据库
2、use database_name //使用database_name数据库
3、create database data_name //创建名为data_name的数据库
4、drop database data_name //删除一个名为data_name的数据库
三、表操作
1、show databases;//列出所有数据库
use 数据库名; //到达某一数据库
show tables //列出所有表
create table tab_name(
id int(10) not null auto_increment primary key,
name varchar(40),
pwd varchar(40)
) charset=gb2312; 创建一个名为tab_name的新表
2、drop table tab_name 删除名为tab_name的数据表
3、describe tab_name //显示名为tab_name的表的数据结构
4、show columns from tab_name //同上
5、delete from tab_name //将表tab_name中的记录清空
6、select * from tab_name //显示表tab_name中的记录
7、mysqldump -uUSER -pPASSWORD --no-data DATABASE TABLE > table.sql //复制表结构
四、修改表结构
1、 ALTER TABLE tab_name ADD PRIMARY KEY (col_name)
说明:更改表得的定义把某个栏位设为主键。
2、ALTER TABLE tab_name DROP PRIMARY KEY (col_name)
说明:把主键的定义删除
3、 alter table tab_name add col_name varchar(20); //在tab_name表中增加一个名为col_name的字段且类型为varchar(20)
4、alter table tab_name drop col_name //在tab_name中将col_name字段删除
5、alter table tab_name modify col_name varchar(40) not null //修改字段属性,注若加上not null则要求原字段下没有数据
SQL Server200下的写法是:Alter Table table_name Alter Column col_name varchar(30) not null;
6、如何修改表名:alter table tab_name rename to new_tab_name
7、如何修改字段名:alter table tab_name change old_col new_col varchar(40); //必须为当前字段指定数据类型等属性,否则不能修改
8、create table new_tab_name like old_tab_name //用一个已存在的表来建新表,但不包含旧表的数据
五、数据的备份与恢复
导入外部数据文本:
1.执行外部的sql脚本
当前数据库上执行:mysql 指定数据库上执行:mysql [表名] 2.数据传入命令 load data local infile "[文件名]" into table [表名];
备份数据库:(dos下)
mysqldump --opt school>school.bbb
mysqldump -u [user] -p [password] databasename > filename (备份)
mysql -u [user] -p [password] databasename
六、卸载
卸载mysql:sudo apt-get remove mysql-server mysql-client
sudo apt-get autoremove
?
1.终端启动MySQL:/etc/init.d/mysql start;(stop ,restart。)
2.登录MySQL:mysql -uroot -p (用root账户登录),然后输入密码;
3.查看所有的数据库名字:show databases;
4.选择一个数据库操作: use database_name;
5.查看当前数据库下所有的表名:show tables;
6.创建一个数据库:create database database_name;
7.删除一个数据库:drop database database_name;
8.创建一个表: create table mytest( uid bigint(20) not null, uname varchar(20) not null);
9.删除一个表: drop table mytest;
10.SQL插入语句:insert into table_name(col1,col2) values(value1,value2);
11.SQL更新语句:update table_name set col1='value1',col2='value2' where where_definition;
12.SQL查询语句:select * from table_name where.......(最复杂的语句)
13.SQL删除语句:delete from table_name where...
14.增加表结构的字段:alert table table_name add column field1 date ,add column field2 time...
15.删除表结构的字段:alert table table_name drop field1;
16.查看表的结构:show columns from table_name;
17.limit 的使用:select * from table_name limit 3;//每页只显示3行
select * from table_name limit 3,4 //从查询结果的第三个开始,显示四项结果。
此处可很好的用来作分页处理。
18.对查询结果进行排序: select * from table_name order by field1,orderby field2;多重排序
19.退出MySQL:exit;
?

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于架构原理的相关内容,MySQL Server架构自顶向下大致可以分网络连接层、服务层、存储引擎层和系统文件层,下面一起来看一下,希望对大家有帮助。

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

mysql的msi与zip版本的区别:1、zip包含的安装程序是一种主动安装,而msi包含的是被installer所用的安装文件以提交请求的方式安装;2、zip是一种数据压缩和文档存储的文件格式,msi是微软格式的安装包。

方法:1、利用right函数,语法为“update 表名 set 指定字段 = right(指定字段, length(指定字段)-1)...”;2、利用substring函数,语法为“select substring(指定字段,2)..”。

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
