mysql database start

First, the relationship between the distinction:

Database server (a computer)

Database management system (software)

Database (db) a folder

A table inside the database file

Records (data) :( plurality of field) line of data

installation

1, to initialize the entire MySQL
storage database generation mysqld --initialize-insecure data directory => File => Record

2, open client:
MySQL-uroot--p

3, in the view of all database directory
show databases;

4. Create a database
create database db1;

5, install windows service
mysqld --install to install windows service
mysqld --remove Delete windows service

6, open the service

Open net start mysql service
shut down service net stop mysql

7, set a password

Password ALTER USER 'root' @ 'localhost' IDENTIFIED BY 'newpassword' here if you just change the current user password can not write the name of the user to write directly to user ()

## Second, the special case (when the root password forgotten):

## When the administrator password is forgotten crack the code to skip the grant tables turned on the server

  1. Kill the process taskkill / F / PID process ID

  2. Open skip command authorization table mysqld --console --skip-grant-tables --shared-memory

  3. Refresh authority FLUSH PRIVILEGES; tell the server to reload the grant tables to account management statement works

  4. 设置密码 ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword'

  5. 最后停止服务器进程重新启动,完毕

修改密码

  1. 登录进入mysql 进行修改 ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword'

  2. 只更改当前登录用户的密码 ALTER USER USER() IDENTIFIED BY 'password';

  3. 命令行更改密码
    mysqladmin -uroot -p 旧密码 password 新密码

三、常用命令:

命令 作用
\s; 查看当前mysql软件的配置
mysql -uroot -p 登录mysql
show datebases 查看所有的数据库
create database db1; 创建数据库
drop database db1; 删除数据库
use db1; 进入/切换数据库
select database(); 查看当前数据库
create user 'name'@'ip' identified by 'pwd' 添加用户
grant insert,select,update on db1.t1 to "user"@"ip"; 为添加的用户配置权限,只有root用户才能配置

表的操作

show tables; 查看当前数据库里的所有的表
create table t1(id int,name char(10)); 创建表
insert into t1(id,name) values(1,'wer'),(2,'sdf'); 插入数据
desc table_name 查看表结构的详细信息
show create table t1; 查看当前这张表
select * from t1; 查看表里的内容
drop table t1; 删除这张表
update t1 set user='123' where id=8; 修改记录
delete from t1 where id=8; 删除记录
alter table t1 change 原字段名字 修改后的名字 字段属性; 修改字段名字
alter table t1 modify 字段名 属性; 修改字段属性
alter table t1 add 字段名 属性; 增加字段
alter table t1 drop 字段名; 删除字段

Guess you like

Origin www.cnblogs.com/whileke/p/11688300.html