mysql
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
mysql [2022/07/19 20:52] – created 85.134.209.200 | mysql [2022/07/20 23:15] (current) – Updated formatting admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== MySQL ====== | ====== MySQL ====== | ||
- | ======Common MYSQL Commands====== | + | =====Common MYSQL Commands===== |
Update information in a Table: | Update information in a Table: | ||
+ | < | ||
| | ||
+ | </ | ||
Alter the Structure of a Table: | Alter the Structure of a Table: | ||
+ | < | ||
alter table abstract_submit modify surname varchar(250); | alter table abstract_submit modify surname varchar(250); | ||
alter table paper_submit add (abstract text); | alter table paper_submit add (abstract text); | ||
- | alter table paper_submit drop primary key; < | + | alter table paper_submit drop primary key; #dont worry, this will only drop the primary key and leave the data and column intact. |
+ | </ | ||
Some databases may not provide the user with "All Privileges" | Some databases may not provide the user with "All Privileges" | ||
+ | < | ||
GRANT ALTER ON db.* TO db@localhost IDENTIFIED BY ' | GRANT ALTER ON db.* TO db@localhost IDENTIFIED BY ' | ||
+ | </ | ||
- | **MYSQL USERS ADD/ REMOVE** | + | =====MYSQL USERS ADD/ REMOVE===== |
+ | < | ||
Add/ Create a New User: | Add/ Create a New User: | ||
GRANT ALL PRIVILEGES | GRANT ALL PRIVILEGES | ||
Line 20: | Line 26: | ||
TO faim@' | TO faim@' | ||
| | ||
+ | </ | ||
Delete a User: | Delete a User: | ||
+ | < | ||
| | ||
drop user user@localhost; | drop user user@localhost; | ||
+ | </ | ||
Remove a Users Privileges: | Remove a Users Privileges: | ||
+ | < | ||
| | ||
ON *.* | ON *.* | ||
FROM davisc@' | FROM davisc@' | ||
+ | </ | ||
=====MYSQLDUMP===== | =====MYSQLDUMP===== | ||
- | Backup MySQL Database:< | + | Backup MySQL Database: |
+ | <code> | ||
| | ||
+ | </ | ||
If you get the following error, you may have to "skip lock tables": | If you get the following error, you may have to "skip lock tables": | ||
+ | < | ||
| | ||
+ | </ | ||
+ | < | ||
| | ||
- | < | + | #Another method: |
| | ||
+ | </ | ||
+ | |||
+ | ===== Importing a MySQL Dump ===== | ||
+ | < | ||
+ | mysql -u username -p database_name < file.sql | ||
+ | </ | ||
===== Setting and Inputting Fixed Variables in MySQL Statements ===== | ===== Setting and Inputting Fixed Variables in MySQL Statements ===== | ||
+ | < | ||
| | ||
Query OK, 0 rows affected (0.05 sec) | Query OK, 0 rows affected (0.05 sec) | ||
| | ||
+ | </ | ||
===== Show colums as Rows ===== | ===== Show colums as Rows ===== | ||
The following switch \G will display information in Groups of Rows instead of Columns. Example: | The following switch \G will display information in Groups of Rows instead of Columns. Example: | ||
+ | < | ||
| | ||
| | ||
- | < | + | #Its quite hard to read and has many many columns. Now try: |
| | ||
- | < | + | #no semi-colon needed. All information is shown in Rows. |
+ | </ | ||
====== Block all MySQL Users Temporarily ====== | ====== Block all MySQL Users Temporarily ====== | ||
+ | < | ||
SHOW VARIABLES LIKE ' | SHOW VARIABLES LIKE ' | ||
SET GLOBAL max_connections = 0; | SET GLOBAL max_connections = 0; | ||
+ | </ | ||
The above locks all people out from the MySQL server. | The above locks all people out from the MySQL server. | ||
Line 63: | Line 89: | ||
**" | **" | ||
- | To see if there are any current connections or processes | + | To see if there are any current connections or processes |
+ | < | ||
SHOW PROCESSLIST; | SHOW PROCESSLIST; | ||
+ | </ | ||
====== Determine Logged in users and their Connections to the DB ====== | ====== Determine Logged in users and their Connections to the DB ====== | ||
+ | < | ||
| | ||
- | < | + | #The above assumes that the mysql root password in stored in .my.cnf |
+ | </ | ||
- | ===== Script to log MySQL users and persistant | + | ===== Script to log MySQL users and persistent |
+ | < | ||
# | # | ||
| | ||
- | < | + | #Create a 5min cron job: |
*/5 * * * * / | */5 * * * * / | ||
+ | </ | ||
====== Repair a Crashed MySQL Table ====== | ====== Repair a Crashed MySQL Table ====== | ||
In case you stumble across an error like: "Table ' | In case you stumble across an error like: "Table ' | ||
+ | < | ||
mysql -u username -p databasename | mysql -u username -p databasename | ||
check table g2_SessionMap; | check table g2_SessionMap; | ||
| | ||
+ | </ | ||
If you enable debug in gallery2 ( $gallery-> | If you enable debug in gallery2 ( $gallery-> | ||
====== Set limits for MySQL usage by Users ====== | ====== Set limits for MySQL usage by Users ====== | ||
To limit a user/ | To limit a user/ | ||
+ | < | ||
| | ||
show grants for user@' | show grants for user@' | ||
Line 98: | Line 132: | ||
grant usage on kartblog.* to kartblog@' | grant usage on kartblog.* to kartblog@' | ||
show grants for kartblog@' | show grants for kartblog@' | ||
- | < | + | #Not sure what max_user_connections is ideal, but will try it at 5. |
+ | </ | ||
- | References: | + | References:\\ |
- | http:// | + | http:// |
- | http:// | + | http:// |
====== Export a MySQL select query ====== | ====== Export a MySQL select query ====== | ||
So I was using mysql> via the command line, and I wanted to export a large select query to a text file. Here is how: | So I was using mysql> via the command line, and I wanted to export a large select query to a text file. Here is how: | ||
+ | < | ||
echo " | echo " | ||
+ | </ | ||
Reference: http:// | Reference: http:// | ||
Line 114: | Line 151: | ||
http:// | http:// | ||
- | http:// | + | http:// |
- | ^ Upgrade issue when tailing daemon.logs after upgrading from mysql-5 to mysql-5.1 | + |
mysql.1658260370.txt.gz · Last modified: 2022/07/19 21:13 (external edit)