SQL 基础

show random password generated after install

$ grep 'temporary password' /var/log/mysqld.log

login mySQL with password

$ mysql -u root -p

change passowrd

mysql> alter user 'root'@'localhost' identified by 'new_passwd'; // length >= 8

Database

show databases

mysql> show databases;

creat databases

$ mysqladmin -u root -p create database_name

import sql file

$ mysql -u root -p database_name < file_name.sql

or

mysql> source file_name.sql;

select database

mysql> use database_name;

delete database

$ mysqladmin -u root -p drop RUNOOB

backup database

$ mysqldump -u root -p table_name > dump.sql

Table

show tables

mysql> show tables;
myaql> desc table_name;

creat table

mysql> create table if not exists t_student (
id bigint(12) primary key,
name varchar(50) not null unique comment '姓名',
age mediumint(6) not null default 1 comment '年龄',
address text nit null default '' comment '地址'
);

import

delete

myaql> drop table table_name;

edit

// add key
mysql> alter table t_student add column_name new_type
// edit key type
mysql> alter table t_student alter column column_name new_data_type;
// delete key
mysql> alter table t_student drop column column_name;
// edit table name
mysql> alter table table_name rename to new_table_name;

Log

// add
insert into t_student (name, age) values (‘mj’, 10);
// delete
delete * wahre id = 2009282828 from t_student;
// select
select name, age from t_student where age > 10 an name like '%Li%' order by age desc, height asc limit 4, 8
// edit
update t_student set name = ‘jack’, age = 20 whare id = 200910102;

results matching ""

    No results matching ""