Home Database Mysql Tutorial mysql简单命令的学习_MySQL

mysql简单命令的学习_MySQL

Jun 01, 2016 pm 01:42 PM
mysql password username

bitsCN.com
一、连接MYSQL。格式: mysql -h主机地址 -u用户名 -p用户密码1、连接到本机上的MYSQL。首先打开DOS窗口,然后进入目录mysql/bin,再键入命令mysql -uroot -p,回车后提示你输密码.注意用户名前可以有空格也可以没有空格,但是密码前必须没有空格,否则让你重新输入密码.如果刚安装好MYSQL,超级用户root是没有密码的,故直接回车即可进入到MYSQL中了,MYSQL的提示符是: mysql>2、连接到远程主机上的MYSQL。    假设远程主机的IP为:110.110.110.110,用户名为root,密码为abcd123。则键入以下命令:mysql -h110.110.110.110 -uroot -p123;(注:u与root之间可以不用加空格,其它也一样)3、退出MYSQL命令: exit (回车)二、修改密码。格式:mysqladmin -u用户名 -p旧密码 password 新密码 (在测试的时候发现没有这个命令,呵呵原来是版本太低了)官网: mysqladmin — Client for Administering a MySQL Serverhttp://dev.mysql.com/doc/refman/5.1/en/mysqladmin.html 1、给root加个密码ab12。首先在DOS下进入目录mysql/bin,然后键入以下命令mysqladmin -u root -password ab12注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。2、再将root的密码改为djg345。mysqladmin -u root -p ab12 password djg345三、增加新用户。(注意:和上面不同,下面的因为是MYSQL环境中的命令,所以后面都带一个分号作为命令结束符)格式:grant select on 数据库.* to 用户名@登录主机 identified by “密码”1、增加一个用户test1密码为abc,让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。首先用root用户连入MYSQL,然后键入以下命令:grant select,insert,update,delete on *.* to [email=test1@”%]test1@”%[/email]” Identified by “abc”;但增加的用户是十分危险的,你想如某个人知道test1的密码,那么他就可以在internet上的任何一台电脑上登录你的mysql数据库并对你的数据可以为所欲为了,解决办法见2。2、增加一个用户test2密码为abc,让他只可以在localhost上登录,并可以对数据库mydb进行查询、插入、修改、删除的操作(localhost指本地主机,即MYSQL数据库所在的那台主机),这样用户即使用知道test2的密码,他也无法从internet上直接访问数据库,只能通过MYSQL主机上的web页来访问了。grant select,insert,update,delete on mydb.* to [email=test2@localhost]test2@localhost[/email] identified by “abc”;    如果你不想test2有密码,可以再打一个命令将密码消掉。grant select,insert,update,delete on mydb.* to [email=test2@localhost]test2@localhost[/email] identified by “”;下篇我是MYSQL中有关数据库方面的操作。注意:你必须首先登录到MYSQL中,以下操作都是在MYSQL的提示符下进行的,而且每个命令以分号结束。一、操作技巧1、如果你打命令时,回车后发现忘记加分号,你无须重打一遍命令,只要打个分号回车就可以了。也就是说你可以把一个完整的命令分成几行来打,完后用分号作结束标志就OK。2、你可以使用光标上下键调出以前的命令。二、显示命令1、显示当前数据库服务器中的数据库列表:mysql> SHOW DATABASES;注意:mysql库里面有MYSQL的系统信息,我们改密码和新增用户,实际上就是用这个库进行操作。2、显示数据库中的数据表:mysql> USE 库名;mysql> SHOW TABLES;3、显示数据表的结构:mysql> DESCRIBE 表名;4、建立数据库:mysql> CREATE DATABASE 库名;5、建立数据表:mysql> USE 库名;mysql> CREATE TABLE 表名 (字段名 VARCHAR(20), 字段名 CHAR(1));6、删除数据库:    mysql> DROP DATABASE 库名;7、删除数据表:mysql> DROP TABLE 表名;8、将表中记录清空:mysql> DELETE FROM 表名;9、显示表中的记录:mysql> SELECT * FROM 表名;10、往表中插入记录:mysql> INSERT INTO 表名 VALUES (”hyq”,”M”);11、更新表中数据:mysql-> UPDATE 表名 SET 字段名1=’a',字段名2=’b’ WHERE 字段名3=’c';12、用文本方式将数据装入数据表中:mysql> LOAD DATA LOCAL INFILE “D:/mysql.txt” INTO TABLE 表名;13、导入.sql文件命令:mysql> USE 数据库名;mysql> SOURCE d:/mysql.sql;14、命令行修改root密码:mysql> UPDATE mysql.user SET password=PASSWORD(’新密码’) WHERE User=’root’;mysql> FLUSH PRIVILEGES;15、显示use的数据库名:mysql> SELECT DATABASE();16、显示当前的user:mysql> SELECT USER(); 新加:当前使用状态mysql>statusmysql  Ver 14.12 Distrib 5.0.45, for Win32 (ia32)Connection id:          6Current database:       数据库名Current user:           root@localhostSSL:                    Not in useUsing delimiter:        ;    Server version:         5.0.45-community-nt-log MySQL Community Edition (GPL)Protocol version:       10Connection:             localhost via TCP/IPServer characterset:    utf8Db     characterset:    utf8Client characterset:    utf8Conn.  characterset:    utf8TCP port:               3306Uptime:                 35 min 48 sec 三、一个建库和建表以及插入数据的实例drop database if exists school; //如果存在SCHOOL则删除create database school; //建立库SCHOOLuse school; //打开库SCHOOLcreate table teacher //建立表TEACHER(id int(3) auto_increment not null primary key,name char(10) not null,    address varchar(50) default ‘深圳’,year date); //建表结束//以下为插入字段insert into teacher values(”,’allen’,'大连一中’,'1976-10-10′);insert into teacher values(”,’jack’,'大连二中’,'1975-12-23′);如果你在mysql提示符键入上面的命令也可以,但不方便调试。(1)你可以将以上命令原样写入一个文本文件中,假设为school.sql,然后复制到c://下,并在DOS状态进入目录[url=file:////mysql//bin]//mysql//bin[/url],然后键入以下命令:mysql -uroot -p密码 source c://school.sql; 也可以将school.sql文件导入数据库中。四、将文本数据转到数据库中1、文本数据应符合的格式:字段数据之间用tab键隔开,null值用[url=file:////n]//n[/url]来代替.例:3 rose 大连二中 1976-10-104 mike 大连一中 1975-12-23假设你把这两组数据存为school.txt文件,放在c盘根目录下。2、数据传入命令 load data local infile “c://school.txt” into table 表名;注意:你最好将文件复制到[url=file:////mysql//bin]//mysql//bin[/url]目录下,并且要先用use命令打表所在的库。    五、备份数据库:(命令在DOS的[url=file:////mysql//bin]//mysql//bin[/url]目录下执行)1.导出整个数据库导出文件默认是存在mysql/bin目录下mysqldump -u 用户名 -p 数据库名 > 导出的文件名mysqldump -u user_name -p123456 database_name > outfile_name.sql2.导出一个表mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名mysqldump -u user_name -p database_name table_name > outfile_name.sql3.导出一个数据库结构mysqldump -u user_name -p -d –add-drop-table database_name > outfile_name.sql-d 没有数据 –add-drop-table 在每个create语句之前增加一个drop table4.带语言参数导出mysqldump -uroot -p –default-character-set=latin1 –set-charset=gbk –skip-opt database_name > outfile_name.sql  作者 wenjinglian bitsCN.com

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

How to open phpmyadmin How to open phpmyadmin Apr 10, 2025 pm 10:51 PM

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

How to use single threaded redis How to use single threaded redis Apr 10, 2025 pm 07:12 PM

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

MySQL and SQL: Essential Skills for Developers MySQL and SQL: Essential Skills for Developers Apr 10, 2025 am 09:30 AM

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

How to build a SQL database How to build a SQL database Apr 09, 2025 pm 04:24 PM

Building an SQL database involves 10 steps: selecting DBMS; installing DBMS; creating a database; creating a table; inserting data; retrieving data; updating data; deleting data; managing users; backing up the database.

See all articles