zoukankan      html  css  js  c++  java
  • mysql

    mac安装mysql数据库及配置环境变量:https://blog.csdn.net/qq_36004521/article/details/80637886

    1. 进入mysql
    mysql -u root -p
    然后输入密码。
    如果密码输错了,会报‘ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)’错误。
    错误解决方案看这里吧:    https://blog.csdn.net/qq_32786873/article/details/79225039
    2.退出mysql
    exit or quit
    
    3.创建数据库
    create database <数据库名>;       ->这个分号很重要啊,注意别用中文分号,看仔细点。
    
    4.显示数据库
    show databases; 
    
    5.删除数据库:
    drop database <数据库名称>;    
    
    6.使用数据库
    use <数据库名称>;
    
    7.数据库表操作
    // 创建表(personId设置了关键值则不能重复)
    create table personTable (personId int, name varchar(20), gender varchar(10), primary key(personId)); 
    
    // 在表中添加新列
    alter table personTable add age int;
    
    // 查看表结构信息
    desc personTable;
    
    // 删除表
    drop table personTable;
    
    // 复制表
    create table personInfo like personTable;
    
    
    -------------------------------------------------
    8. 简单sql语句
    // 查看数据
    select * from personInfo; // 查询全部
    select * from personInfo where age = 35; // 条件查询
    
    // 插入数据
    insert into personInfo (personId, name, gender, age) values (1000, 'devZhang', "male", 35);
    
    1 双引号中的是一个标准的SQL语句,把他拿到mysql中可以单独执行 
    
    2 因为是SQL语句,字符型的字段的值要用单引号括起来加以标注 
    字符串类型的变量也要加''
    
    // 更新数据
    update personInfo set age = 25,name = "uiChen",gender='female' where personId = 1001;
    
    // 删除数据
    delete from personInfo where age = 23;
    

    错误处理:

    1. 连接Navicat与mysql时报错,注意,这个问题是 MySQL 的问题,不是客户端问题,
    错误信息   Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/mysql/lib/plugin/caching_sha2_password.so, 2): image not found
    
    解决方法:mysql > ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpassword';
    
    2. 对某个数据库或者里面的表进行操作时,动不动就卡死,或者出现Lost connection to MySQL server during query
    通过 show processlist 一看,满屏都是 Waiting for table metadata lock 状态的连接。一个一个id kill 不过来,可以通过重启mysql服务
    
  • 相关阅读:
    html php插入百度地图定位
    thinkphp验证功能(部分)
    thinkphp用ajax注册及检测个人见解
    文件系统处理_下
    文件系统处理
    jQuery ajax
    jquery(复选框全选)
    jquery(鼠标)
    找房子(数据库应用)
    php基础题
  • 原文地址:https://www.cnblogs.com/plusUltra/p/10577180.html
Copyright © 2011-2022 走看看