A little experience using mysql on Ubuntu
Install mysql
- sudo apt-get install net-tools 【sudo: netstat: command not found】
- sudo netstat -tap | grep mysql [Check whether mysql is installed successfully, if there is nothing, it means it is not installed, then execute the following three commands]
- sudo apt-get install mysql-server
- sudo apt install mysql-client
- sudo apt install libmysqlclient-dev
- sudo netstat -tap | grep mysql
Create a database: create database test
show databases; view which databases are there
Create a table: create table test (
)
View table: use describe table; view (Note: you must use the use table to enter the database before you can use this command)
Delete table:
drop table;truncate (table);
truncate is to delete all data in the table
Drop is to delete the table directly, it cannot be retrieved.
delete also deletes data in the table, but can be used in conjunction with where to delete specific rows;
- - Delete all data in the table
deletefrom user;--Delete specified line
deletefrom user where username ='Tom';
View the data of the table:
Use select*from table;View data
Use show tables to view the table name under test
Reset the mysql password to root
method 1:
- sudo cat /etc/mysql/debian.cnf【View original password】
- 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 【Restart the database】
- mysql -uroot -p [Login]
- select version() from dual; [Check the version number of 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'; [Reset password]
- quit/exit 【Exit】
- sudo service mysql restart 【Restart the database】
- mysql -uroot -p [Login]