UPDATE tbl_name SET col_name = value WHERE what_record_to_update;
DELETE FROM tbl_name WHERE which_records_to_delete;
CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
CREATE USER 'monty'@'%' IDENTIFIED BY 'some_pass';
CREATE USER 'admin'@'localhost';
GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%' WITH GRANT OPTION;
GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost';
Two of the accounts have a user name of monty and a password of some_pass. Both accounts are superuser accounts with full privileges to do anything. One account ('monty'@'localhost') can be used only when connecting from the local host. The other ('monty'@'%') can be used to connect from any other host.
One account has a user name of admin and no password. This account can be used only by connecting from the local host.
To check the privileges for an account, use SHOW GRANTS:
SHOW GRANTS FOR 'admin'@'localhost';
To check the MySQL server's listen address use netstat as root:
netstat -tlnp
To make MySQL listen on all available IP addresses, edit /etc/mysql/my.cnf and comment out the line:
#bind-address = 127.0.0.1
| Global attributes:
NULL or NOT NULL, DEFAULT default_value Exception: No DEFAULT for TIMESTAMP, BLOB, & TEXT and any AUTO_INCREMENT column. |
||
|---|---|---|
| Column type | Allowed Attributes | Default value |
| TINYINT SMALLINT MEDIUMINT INT BIGINT |
AUTO_INCREMENT UNSIGNED ZEROFILL |
(in lieu of explicit DEFAULT attribute in type spec) NULL if column can be NULL or 0 if NOT NULL |
| FLOAT DOUBLE DECIMAL |
UNSIGNED ZEROFILL |
NULL or 0 |
| CHAR VARCHAR |
BINARY CHARACTER SET |
NULL or "" |
| TINYBLOB BLOB MEDIUMBLOB LONGBLOB |
None | NULL or "" |
| TINYTEXT TEXT MEDIUMTEXT LONGTEXT |
CHARACTER SET | NULL or "" |
| ENUM | None | NULL or first enumeration |
| SET | None | NULL or "" |
| DATE | None | NULL or '0000-00-00' |
| TIME | None | NULL or '00:00:00' |
| DATETIME | None | NULL or '0000-00-00 00:00:00' |
| TIMESTAMP | None | Current date and time for the first TIMESTAMP column 0 for any others. Setting to NULL sets to current date and time |
| YEAR | None | NULL or 0000 or 00 |
me@my:~ $ x=1; while read a; do echo $x - $a; let x++; done < <(mysql -sse 'show databases') 1 - information_schema 2 - mysql me@my:~ $
The query string is based on having a ~/.my.cnf file so that variables like host, user, and password do not have to be included.
The two silent options (-s) turn off both column headings, and the ascii boxes.
The -e option means execute the query and quit. The query string should be
enclosed in single quotes to protect it from the shell.
Multiple queries, separated by semicolons are allowed.
The < <(command) shell construct lets you redirect the command output into the
while block.
The space between the parenthesis is mandatory.
See also Bash and MySQL