Login (from unix shell) use -h only if needed
# [mysql dir]/bin/mysql -h hostname -u root -pCreate a database on the sql server.
mysql> create database [databasename];List all databases on the sql server.
mysql> show databases;Switch to a database.
mysql> use [db name];To see all the tables in the db.
mysql> show tables;To see database’s field formats.
mysql> describe [table name];To delete a db.
mysql> drop database [database name];To delete a table.
mysql> drop table [table name];Show all data in a table.
mysql> SELECT * FROM [table name];Returns the columns and column information pertaining to the designated table.
mysql> show columns from [table name];Show certain selected rows with the value “whatever”.
mysql> SELECT * FROM [table name] WHERE [field name] = “whatever”;Show all records containing the name “jurank” AND the phone number ’1212121′.
mysql> SELECT * FROM [table name] WHERE name = “jurank” AND phone_number = ’1212121′;Show all records not containing the name “jurank” AND the phone number ’1212121′ order by the phone_number field.
mysql> SELECT * FROM [table name] WHERE name != “jurank” AND phone_number = ’1212121′ order by phone_number;Show all records starting with the letters ‘jurank’ AND the phone number ’1212121′.
mysql> SELECT * FROM [table name] WHERE name like “jurank%” AND phone_number = ’1212121′;Show all records starting with the letters ‘jurank’ AND the phone number ’1212121′ limit to records 1 through 5.
mysql> SELECT * FROM [table name] WHERE name like “jurank%” AND phone_number = ’1212121′ limit 1,5;Use a regular expression to find records. Use “REGEXP BINARY” to force case-sensitivity. This finds any record beginning with a.
mysql> SELECT * FROM [table name] WHERE rec RLIKE “^a”;Show unique records.
mysql> SELECT DISTINCT [column name] FROM [table name];Show selected records sorted in an ascending (asc) or descending (desc).
mysql> SELECT [col1],[col2] FROM [table name] ORDER BY [col2] DESC;Return number of rows.
mysql> SELECT COUNT(*) FROM [table name];Sum column.
mysql> SELECT SUM(*) FROM [table name];Join tables on common columns.
mysql> select lookup.illustrationid, lookup.personid,person.birthday from lookup left join person on lookup.personid=person.personid=statement to join birthday in person table with primary illustration id;Creating a new user. Login as root. Switch to the MySQL db. Make the user. Update privs.
# mysql -u root -pmysql> use mysql;
mysql> INSERT INTO user (Host,User,Password) VALUES(‘%’,'username’,PASSWORD(‘password’));
mysql> flush privileges;
Change a users password from unix shell.
# [mysql dir]/bin/mysqladmin -u username -h hostname.blah.org -p password ‘new-password’Change a users password from MySQL prompt. Login as root. Set the password. Update privs.
# mysql -u root -pmysql> SET PASSWORD FOR ‘user’@'hostname’ = PASSWORD(‘passwordhere’);
mysql> flush privileges;
Recover a MySQL root password. Stop the MySQL server process. Start again with no grant tables. Login to MySQL as root. Set new password. Exit MySQL and restart MySQL server.
# /etc/init.d/mysql stop# mysqld_safe –skip-grant-tables &
# mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD(“newrootpassword”) where User=’root’;
mysql> flush privileges;
mysql> quit
# /etc/init.d/mysql stop
# /etc/init.d/mysql start
Set a root password if there is on root password.
# mysqladmin -u root password newpasswordUpdate a root password.
# mysqladmin -u root -p oldpassword newpasswordAllow the user “bob” to connect to the server from localhost using the password “passwd”. Login as root. Switch to the MySQL db. Give privs. Update privs.
# mysql -u root -pmysql> use mysql;
mysql> grant usage on *.* to bob@localhost identified by ‘passwd’;
mysql> flush privileges;
Give user privilages for a db. Login as root. Switch to the MySQL db. Grant privs. Update privs.
# mysql -u root -pmysql> use mysql;
mysql> INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES (‘%’,'databasename’,'username’,'Y’,'Y’,'Y’,'Y’,'Y’,'N’);
mysql> flush privileges;
or
mysql> grant all privileges on databasename.* to username@localhost;
mysql> flush privileges;
No comments:
Post a Comment
Terima kasih atas komentarnya