SQL examples

Semplici esempi

mysql -u <utente> -p
show databases;
drop database <dbname>;
use <db_name>;
show tables;
show columns from <table_name>;
rename table <table_name> to <new_table_name>;
select * from <table_name> where <column_name> = <value>;
alter table <table_name> add column <column_name> <column_type>;
alter table <table_name> modify <column_name> <new_type>;
delete from <table_name> where <column_name> = '<value>';


alter table <col_name> change <fieldname> <fieldname> <field_new_type>;
alter table <col_name> modify <fieldname> <field_new_type>;

How to Reset a MySQL Password in 5 Easy Steps

  1. Stop the mysqld daemon process.
  2. Start the mysqld daemon process with the —skip-grant-tables option.
  3. Start the mysql client with the -u root option.
  4. Execute the UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root'; command
  5. Execute the FLUSH PRIVILEGES; command.

Create user/db and grants privileges on new db

CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON new_db.* TO 'new_user'@'localhost';
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.