Ubuntu 上使用mysql一点小经验

  • 2019 年 12 月 19 日
  • 筆記

安装mysql

  • sudo apt-get install net-tools 【sudo: netstat: command not found】
  • sudo netstat -tap | grep mysql 【查看mysql是否安装成功,如果什么也没有,表示没有安装,那么执行下面三条命令】
  • sudo apt-get install mysql-server
  • sudo apt install mysql-client
  • sudo apt install libmysqlclient-dev
  • sudo netstat -tap | grep mysql

创建database:create database test

show databases;查看有哪些数据库

创建表:create table test (

查看表:使用describe 表;查看(注:一定要使用use 表进入数据库之后才能使用这个命令)

删除表:

drop table 表;truncate (table);  truncate 是删除表中所有数据  drop 是直接将表格删除,无法找回。

delete 也是删除表中数据,但可以与where连用,删除特定行;

-- 删除表中所有数据  delete from user;  -- 删除指定行  delete from user where username ='Tom';

查看表的数据:

使用select * from 表;查看数据    使用show tables 查看test下的表名

重置mysql的密码为root

方法1:

  • sudo cat /etc/mysql/debian.cnf【查看原来的密码】
  • sudo mysql -uroot
  • use mysql
  • update mysql.user set authentication_string=password('root') where user='root' and Host ='localhost';
  • update user set plugin="mysql_native_password";
  • flush privileges;
  • quit
  • sudo service mysql restart 【重启数据库】
  • mysql -uroot -p 【登陆】
  • select version() from dual; 【查看mysql的版本号:5.7.24-0ubuntu0.18.10.1(Ubuntu)】
  • sudo cat /etc/mysql/debian.cnf
  • mysql -u root -p
  • ALTER USER root@localhost IDENTIFIED BY 'root'; 【重置密码】
  • quit/exit 【退出】
  • sudo service mysql restart 【重启数据库】
  • mysql -uroot -p 【登陆】
Exit mobile version