search

MySQL常用操作

Jun 07, 2016 pm 03:14 PM
linuxmysqlCommonly usedoperateCommunityforumEnter

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 通过命令行启动、停止MySQL服务器:start: net start mysql stop: net stop mysql 连接MySQL服务器:\mysql -h127.0.0.1 -uroot -p断开MySQL服务器:mysqlquit; 创建数据库:create database db_n

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  通过命令行启动、停止MySQL服务器:start: net start mysql stop: net stop mysql

  连接MySQL服务器:\>mysql -h127.0.0.1 -uroot -p断开MySQL服务器:mysql>quit;

  创建数据库:create database db_name;查看数据库:show databases;选择数据库:use db_name;删除数据库:drop database db_name;

  创建数据库:create [temporary] table [if not exists] tabl_name [(create_definition,……)][table_options][select_statement] temporary 如果使用此关键字,表示创建一个临时表if not exists 该关键字用于避免表存在时产生错误create_definition 表的列属性,MySQL要求在创建表时,至少包含一列table_options 表的一些特性参数select_statement select语句描述部分,用它可以快速创建表下面介绍列属性create_definition部分,具体格式:col_name type [not null|null][default default_value][auto_increment][primary key] [reference_definition] col_name 字段名type 字段类型not null|null 指出该列是否允许是空值default default_value 表示默认值auto_increment 表示是否自动编号,每个表只能有一个auto_increment列,并且必须被索引primary key 表示是否为主键reference_difinition 为字段添加注释

  查看表结构:desc/describe tbl_name [col_name];

  修改表结构:alter table tbl_name   alter_spec[,alter_spec] alter_spec:add [column] create_definition [first|after col_name] //添加新字段add index [index_name](index_col_name,……) //添加索引名称add primary key (index_col_name,……)//添加主键名称add unique [index_name](index_col_name,……)//添加唯一索引alter [column] col_name{set default literal|drop default} //修改字段名称change [column] old_col_name create_definition //修改字段类型modify [column] create_definition //修改子句定义字段drop [column] col_name //删除字段名称drop primary key //删除主键名称drop index index_name //删除索引名称rename [as] new_tbl_name //更改表明重命名表:rename table tbl_name_1 to tbl_name_2;删除表:drop table [if exists] tbl_name;

  数据库备份:\>mysqldump -uusername -ppassword db_name > c:\db.txt数据库恢复:mysql -uusername -ppassword db_name

MySQL常用操作

Statement
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
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment