Mysql学习笔记

139 阅读1分钟

mysql

install

windows

mysql installer can finish almost all of the things of configuring and installing. There have two programs should be noticed,MySQL Server which is the main application to deploy your database or something else. MySQL WorkBench is a program graphical to control your database, server etc. Remember when your configure the MySQL Server, the user should act the actual effects, such as Admin or Database manager.

connect

  • When u connect to the server.

create databese xxx; (ctrl+enter execute current line)

usage

  • create table for the database
create table `database's name`.`table's name`(
    command
)

TIPS

  • tips:when u write your page with idea,and indent the row too behind,it will be automaticaliy code snippet

  • FUNCTIONPROCEDURE,除了function只能返回一个函数外,其他基本一样

  • while和创建过程

flowchat
st=>start: create function name params returns type charset name;
op1=>operation: begin
op2=>operation: declare name type;
op3=>operation: statement
op4=>operation: end while
op5=>operation: statement
cond1=>condition: while condition do
e1=>end: http://tyrantqiao.github.io/Blog

st->op1->op2->cond1
cond1(yes)->op4->e1
cond1(no)->op5->cond1
  • repeat
repeat
    statement
until condition
end repeat
  • if-else
if condition then
    statement
else
    statement
end if

密码设置

忘记密码

  • 首先找到.cnf配置文件,有很多个,按优先次序寻找即可。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Tvau9HWc-1604822322783)(/cnf.png)]

  • 然后打开cnf文件在里面添加以下代码
[mysqld]
skip-grant-tables

加入这段语句后执行/etc/init.d/mysql restart重启mysql服务后登陆mysql时将不需要密码,即执行mysql -u root -p然后回车即可登录

修改密码

执行以下语句更改密码update mysql.user set authentification_string=password('xxxxxx') where user='root' and host='localhost'

然后执行flush privileges即可更改密码

当更改完密码后记得将前面设置的内容删除,不然登录仍然是不用密码的

修改登录权限

赋予所有人登录权限,以root+密码的形式登录

grant all privileges on *.* to 'root'@'%' INDETIFIED BY 'password' WITH GRANT OPTION;
flush privileges;

sql

time_format()

参考这里

# 分钟是%i 具体规则上网百度吧 
select DATE_FORMAT(time_column,"%Y %m %d %h %i %s")