Easier way to access mysql database tables? - mysql

In postgresql all you needed to do was type in postgres <database_name>
to access the database. In MySql, you need to do this:
mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 52
Server version: 5.7.20 Homebrew
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use arthouse_development
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from catalog_items;
Empty set (0.00 sec)
mysql> select * from catalog_items
-> ;
Empty set (0.00 sec)
mysql> select * from users;
Empty set (0.01 sec)
mysql> select * from users
-> ;
Empty set (0.00 sec)
Is there a way to not have to specify the user name and specify the database all in one line?
How do you see all the tables in mysql once inside the database?

Use the -D option of the program mysql the default login with a database.
The -p option let's you enter a password into the mysql program
C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql -u root -p -D stackoverflow
Enter password: **
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.20-log MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Confirm we are using the database stackoverflow.
mysql> select database();
+---------------+
| database() |
+---------------+
| stackoverflow |
+---------------+
1 row in set (0.00 sec)
How do you see all the tables in mysql once inside the database?
mysql> show tables;
+-------------------------+
| Tables_in_stackoverflow |
+-------------------------+
| baskets |
| baskets_fruits |
| conditions |
| employee |
| employees |
| hugetable |
| kanji |
| newtable |
| result |
| t1 |
| t2 |
| table1 |
| table_test |
| temp |
| test |
| testing |
| word |
+-------------------------+
17 rows in set (0.00 sec)
Or by using information_schema.TABLES table
mysql> SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'stackoverflow';
+----------------+
| TABLE_NAME |
+----------------+
| baskets |
| baskets_fruits |
| conditions |
| employee |
| employees |
| hugetable |
| kanji |
| newtable |
| result |
| t1 |
| t2 |
| table1 |
| table_test |
| temp |
| test |
| testing |
| word |
+----------------+
17 rows in set (0.00 sec)

Other answers mention the --database / -D option, but you don't even need that.
https://dev.mysql.com/doc/refman/5.7/en/mysql.html shows the simpler example:
Using mysql is very easy. Invoke it from the prompt of your command
interpreter as follows:
shell> mysql db_name
In other words, exactly like the usage you showed for postgres <database_name>.
You may also need to supply username and password to authenticate for the MySQL instance, but I prefer to put those into an option file so I don't have to type them repeatedly.
$ cat ~/.my.cnf
[client]
username = scott
password = tiger
See https://dev.mysql.com/doc/refman/5.7/en/option-files.html for more on these files.
There's also an optional way to store the user credentials encrypted. For this https://dev.mysql.com/doc/refman/5.7/en/mysql-config-editor.html
Any software is easier to use if you try reading a little bit of the documentation! :-)

Using man mysql to view the mysql manpage you'll find the -D flag:
ยท --database=db_name, -D db_name
The database to use. This is useful primarily in an option file.

Related

permission errors on database for full access user

I am getting an error (on MySQL 5.7.25-google in Google cloud while locally MySQL 5.7.29, it works fine)
Google Cloud, I run (NOTE: show tables shows this table existing from this same user!!!)
mysql> show index from customers;
ERROR 1146 (42S02): Table 'authtables.customers' doesn't exist
and locally (same user and password and setup), I get
mysql> SHOW INDEX FROM customers;
+-----------+------------+------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-----------+------------+------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| customers | 0 | PRIMARY | 1 | id | A | 2 | NULL | NULL | | BTREE | | |
Of course, the command SHOW TABLES; works the same on both and shows the CUSTOMERS table in both!!! grrrr.
I followed the accepted answer in the link below EXCEPT for 1 minor detail for setup of 'authservice' user to 'authtables' database...
Mysql adding user for remote access
The ONE detail is my grant statements were authtables.* so that the user had full access to the authtables database and nothing else.
NEXT is my show grants command in GCP and locally which yield the EXACT same result but in case I am missing a typo, here is the GCP then the local result
mysql> show grants for 'authservice'#'localhost';
+---------------------------------------------------------------------+
| Grants for authservice#localhost |
+---------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'authservice'#'localhost' |
| GRANT ALL PRIVILEGES ON `authtables`.* TO 'authservice'#'localhost' |
+---------------------------------------------------------------------+
2 rows in set (0.08 sec)
local result is
mysql> show grants for 'authservice'#'localhost';
+---------------------------------------------------------------------+
| Grants for authservice#localhost |
+---------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'authservice'#'localhost' |
| GRANT ALL PRIVILEGES ON `authtables`.* TO 'authservice'#'localhost' |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)
For completeness...
GCP version: Server version: 5.7.25-google-log (Google)
local version: Server version: 5.7.29 MySQL Community Server (GPL)
WOW, crap, what is 5.7.25-google-log...ICK. I wonder if it has a bug here.
Also, why is grant have . when I look at my history in mysql to verify, I clearly did authtables.* EVERY time!!!
Then, what happened to the 'authservice'#'%' grant as I don't see that either?
Anyone have any idea how to setup google cloud mysql so I have a user with full access to the database so he is restricted to that database? This seems kind of like some sort of google bug or am I doing something wrong?
thanks,
Dean
OMG, google's mysql 'table names' are CASE SENSITIVE!!! what the heck.
I have to do
show index from CUSTOMERS;
OR
SHOW INDEX FROM CUSTOMERS;
BUT THIS DOES NOT WORK
show index from customers;
ouch! posted this to help the next person out hopefully.

Problems setting up SSL connections for MySQL on Ubuntu 14.04

I've been banging my head for a few days on this and I'm really at the end of my rope...
I'm trying to set up SSL connections on MySQL 5.7.10 running on ubuntu 14.04 and no matter what I do, the user required to use SSL is always rejected with access denied when trying to connect.
I was able to set up SSL easily on Windows (our dev machines) but for the love of me cannot get it to work on Linux.
I tried to use the certificates provided when installing MySQL (located in the /var/lib/mysql directory). I also tried to generate new ones using this procedure. I even tried to import the certificates that I generated using MySQL Workbench on Windows (the ones that actually worked on windows) but nothing works.
When starting up MySQL, SSL seems to be okay, as I only get this in /var/log/mysql/err.log
2015-12-17T18:25:32.687582Z 0 [Warning] CA certificate /var/lib/mysql/ca.pem is self signed.
SSL is ON in MySQL
mysql> SHOW VARIABLES LIKE '%SSL%';
+---------------+--------------------------------+
| Variable_name | Value |
+---------------+--------------------------------+
| have_openssl | YES |
| have_ssl | YES |
| ssl_ca | /var/lib/mysql/ca.pem |
| ssl_capath | |
| ssl_cert | /var/lib/mysql/server-cert.pem |
| ssl_cipher | |
| ssl_crl | |
| ssl_crlpath | |
| ssl_key | /var/lib/mysql/server-key.pem |
+---------------+--------------------------------+
I've put the paths to the server and client certificates in the /etc/mysql/my.cnf
[client]
# SSL Settings
ssl-ca=/var/lib/mysql/ca.pem
ssl-cert=/var/lib/mysql/client-cert.pem
ssl-key=/var/lib/mysql/client-key.pem
[mysqld]
# SSL Settings
ssl-ca=/var/lib/mysql/ca.pem
ssl-cert=/var/lib/mysql/server-cert.pem
ssl-key=/var/lib/mysql/server-key.pem
I even tried to disabled appArmor for mysql in case that would do it, bot I alwas get the sema result when trying to connect a test user requiring ssl as such:
CREATE USER 'test'#'localhost' IDENTIFIED BY 'test';
GRANT USAGE ON *.* TO 'test'#'localhost' REQUIRE ssl;
FLUSH PRIVILEGES;
When trying to connect:
> /usr/bin$ mysql -u test -p
Enter password:
ERROR 1045 (28000): Access denied for user 'test'#'localhost' (using password: YES)
Same thing when manually specifying the client certificates:
> mysql --ssl-ca=/var/lib/mysql/ca.pem --ssl-cert=/var/lib/mysql/client-cert.pem --ssl-key=/var/lib/mysql/client-key.pem --host=localhost --user=test --password
Enter password:
ERROR 1045 (28000): Access denied for user 'test'#'localhost' (using password: YES)
Does anybody have any idea? I fail to see why a setuyp that works fine on windows would give me such grief on linux.
Is there a way to debug this further?
Thansk in advance
/Sebas
My test:
error.log:
[Warning] CA certificate ca.pem is self signed.
$ sudo mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.10 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SELECT VERSION(); -- MySQL Community Server
+-----------+
| VERSION() |
+-----------+
| 5.7.10 |
+-----------+
1 row in set (0.00 sec)
mysql> SHOW VARIABLES LIKE '%ssl%';
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| have_openssl | YES |
| have_ssl | YES |
| ssl_ca | ca.pem |
| ssl_capath | |
| ssl_cert | server-cert.pem |
| ssl_cipher | |
| ssl_crl | |
| ssl_crlpath | |
| ssl_key | server-key.pem |
+---------------+-----------------+
9 rows in set (0.00 sec)
mysql> CREATE USER 'test'#'localhost' IDENTIFIED BY 'test' REQUIRE SSL;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
$ mysql -u test -p
Enter password:
ERROR 1045 (28000): Access denied for user 'test'#'localhost' (using password: YES)
$ mysql -u test -p --ssl
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.7.10 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
You are enforcing ssl conection via unix socket. Please consider
switching ssl off as it does not make connection via unix socket
any more secure.
mysql> SHOW SESSION STATUS LIKE '%Ssl_version%';
+---------------+---------+
| Variable_name | Value |
+---------------+---------+
| Ssl_version | TLSv1.1 |
+---------------+---------+
1 row in set (0.00 sec)
UPDATE: The test details.
mysqld.cnf:
[client]
...
# SSL Settings
ssl-ca=/var/lib/mysql/ca.pem
ssl-cert=/var/lib/mysql/client-cert.pem
ssl-key=/var/lib/mysql/client-key.pem
[mysqld]
...
# SSL Settings
ssl-ca=/var/lib/mysql/ca.pem
ssl-cert=/var/lib/mysql/server-cert.pem
ssl-key=/var/lib/mysql/server-key.pem
Yes, certificates are auto-generated by MySQL. See 6.3.13 Creating SSL and RSA Certificates and Keys. Check the security permissions to access the certificates.
error.log:
[Warning] CA certificate /var/lib/mysql/ca.pem is self signed.
$ sudo mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.10 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SELECT VERSION(); -- MySQL Community Server
+-----------+
| VERSION() |
+-----------+
| 5.7.10 |
+-----------+
1 row in set (0.00 sec)
mysql> SHOW VARIABLES LIKE '%ssl%';
+---------------+--------------------------------+
| Variable_name | Value |
+---------------+--------------------------------+
| have_openssl | YES |
| have_ssl | YES |
| ssl_ca | /var/lib/mysql/ca.pem |
| ssl_capath | |
| ssl_cert | /var/lib/mysql/server-cert.pem |
| ssl_cipher | |
| ssl_crl | |
| ssl_crlpath | |
| ssl_key | /var/lib/mysql/server-key.pem |
+---------------+--------------------------------+
9 rows in set (0,01 sec)
mysql> CREATE USER 'test'#'localhost' IDENTIFIED BY 'test' REQUIRE SSL;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
$ mysql -u test -p
Enter password:
ERROR 1045 (28000): Access denied for user 'test'#'localhost' (using password: YES)
$ mysql -u test -p --ssl
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.7.10 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
You are enforcing ssl conection via unix socket. Please consider
switching ssl off as it does not make connection via unix socket
any more secure.
mysql> SHOW SESSION STATUS LIKE '%Ssl_version%';
+---------------+---------+
| Variable_name | Value |
+---------------+---------+
| Ssl_version | TLSv1.1 |
+---------------+---------+
1 row in set (0.00 sec)

Common_schema function get_option not found after installation

So I've installed common_schema to my mysql server and tried to do action with get_option function.
My SQL:
SELECT *, ((get_option("program_invested_details", "received") * 100) / get_option("program_invested_details", "invested")) AS PERCENT_TOTAL FROM hp_programs_list WHERE program_add_status = 4 AND program_status = 1 ORDER BY PERCENT_TOTAL DESC
but it seems, that get_option function doesn't work, becouse I got this error:
FUNCTION hyips_database.get_option does not exist
my DB structure:
A little test:
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8
Server version: 5.5.31-0ubuntu0.13.04.1 (Ubuntu) Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| common_schema |
| mydb |
| mysql |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.00 sec)
mysql> SELECT * FROM `common_schema`.`status`\G
*************************** 1. row ***************************
project_name: common_schema
version: 2.2
revision: 523
install_time: 2015-01-01 00:00:01
install_success: 1
base_components_installed: 1
innodb_plugin_components_installed: 1
percona_server_components_installed: 0
install_mysql_version: 5.5.31-0ubuntu0.13.04.1
install_sql_mode: NO_AUTO_VALUE_ON_ZERO
1 row in set (0.00 sec)
mysql> USE `test`;
Database changed
mysql> SELECT `get_option`('{name: "Wallace", num_children: 0, "pet": Gromit}', 'pet') `result`;
ERROR 1305 (42000): FUNCTION test.get_option does not exist
mysql> SELECT `common_schema`.`get_option`('{name: "Wallace", num_children: 0, "pet": Gromit}', 'pet') `result`;
+--------+
| result |
+--------+
| Gromit |
+--------+
1 row in set (0.00 sec)

Table 'mysql.user' doesn't exist:ERROR

I am creating a db in mysql for a java program.My program works well in my friends system.But I have some problem with my mysql.
The query is below:
mysql> create database sampledb;
Query OK, 1 row affected (0.00 sec)
mysql> use sampledb;
Database changed
mysql> create user zebronics identified by 'zebra123';
ERROR 1146 (42S02): Table 'mysql.user' doesn't exist
I cant create any user for my db.Please help??
My solution was to run
mysql_upgrade -u root
Scenario: I updated the MySQL version on my Mac with 'homebrew upgrade'. Afterwards, some stuff worked, but other commands raised the error described in the question.
Looks like something is messed up with your MySQL installation. The mysql.user table should definitely exist. Try running the command below on your server to create the tables in the database called mysql:
mysql_install_db
If that doesn't work, maybe the permissions on your MySQL data directory are messed up. Look at a "known good" installation as a reference for what the permissions should be.
You could also try re-installing MySQL completely.
Same issue here as lxxxvi describes. Running
mysql_upgrade -u root
allowed me to then successfully enter a password that
mysql_secure_installation
was waiting for.
Your database may be corrupt. Try to check if mysql.user exists:
use mysql;
select * from user;
If these are missing you can try recreating the tables by using
mysql_install_db
or you may have to clean (completely remove it) and reinstall MySQL.
show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| datapass_schema |
| mysql |
| test |
+--------------------+
4 rows in set (0.05 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables
-> ;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
23 rows in set (0.00 sec)
mysql> create user m identified by 'm';
Query OK, 0 rows affected (0.02 sec)
check for the database mysql and table user as shown above if that dosent work, your mysql installation is not proper.
use the below command as mention in other post to install tables again
mysql_install_db
You can run the following query to check for the existance of the user table.
SELECT * FROM information_schema.TABLES
WHERE TABLE_NAME LIKE '%user%'
See if you can find a row with the following values in
mysql user BASE TABLE MyISAM
If you cant find this table look at the following link to rebuild the database How to recover/recreate mysql's default 'mysql' database
Try run mysqladmin reload, which is located in /usr/loca/mysql/bin/ on mac.
'Error Code: 1046'.
This error shows that the table does not exist may sometimes be caused by having selected a different database and running a query referring to another table. The results indicates
'No database selected Select the default DB to be used by double-clicking its name in the SCHEMAS list in the sidebar'.
Will solve the issue and it worked for me very well.
It sometime happens when you run the grant/ privileges query on an empty database

syntax for before update trigger to generate hash

How do I get the hash generated after updates?
thufir#dur:~$
thufir#dur:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 138
Server version: 5.1.58-1ubuntu1 (Ubuntu)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use nntp;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+---------------------+
| Tables_in_nntp |
+---------------------+
| articles |
| newsgroups |
| newsgroups_articles |
+---------------------+
3 rows in set (0.00 sec)
mysql> describe newsgroups;
+-----------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| newsgroup | longtext | NO | | NULL | |
| hash | char(32) | NO | | NULL | |
+-----------+----------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
mysql> show triggers;
+-----------+--------+------------+-----------------------------------------------------+--------+---------+----------+----------------+----------------------+----------------------+--------------------+
| Trigger | Event | Table | Statement | Timing | Created | sql_mode | Definer | character_set_client | collation_connection | Database Collation |
+-----------+--------+------------+-----------------------------------------------------+--------+---------+----------+----------------+----------------------+----------------------+--------------------+
| make_hash | INSERT | newsgroups | BEGIN
set new.hash = md5(new.newsgroup);
END | BEFORE | NULL | | root#localhost | utf8 | utf8_general_ci | latin1_swedish_ci |
+-----------+--------+------------+-----------------------------------------------------+--------+---------+----------+----------------+----------------------+----------------------+--------------------+
1 row in set (0.00 sec)
mysql>
mysql>
mysql> DELIMITER $$
mysql>
mysql> USE `nntp`$$
Database changed
mysql> CREATE
-> TRIGGER `nntp`.`make_hash_update`
-> AFTER UPDATE ON `nntp`.`newsgroups`
-> FOR EACH ROW
-> BEGIN
-> set old.hash = md5(new.newsgroup);
-> END$$
ERROR 1362 (HY000): Updating of OLD row is not allowed in trigger
mysql>
mysql> quit;
-> exit
-> ^CCtrl-C -- exit!
Aborted
thufir#dur:~$
Also, from the workbench, I see the old trigger:
but don't see how to add an additional trigger.
It's not after update, it's before update, and new. Don't quite understand the syntax, but this at least doesn't generate syntax errors. Would've like to have use the workbench:
thufir#dur:~$
thufir#dur:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 144
Server version: 5.1.58-1ubuntu1 (Ubuntu)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use nntp;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show triggers;
+-----------+--------+------------+-----------------------------------------------------+--------+---------+----------+----------------+----------------------+----------------------+--------------------+
| Trigger | Event | Table | Statement | Timing | Created | sql_mode | Definer | character_set_client | collation_connection | Database Collation |
+-----------+--------+------------+-----------------------------------------------------+--------+---------+----------+----------------+----------------------+----------------------+--------------------+
| make_hash | INSERT | newsgroups | BEGIN
set new.hash = md5(new.newsgroup);
END | BEFORE | NULL | | root#localhost | utf8 | utf8_general_ci | latin1_swedish_ci |
+-----------+--------+------------+-----------------------------------------------------+--------+---------+----------+----------------+----------------------+----------------------+--------------------+
1 row in set (0.00 sec)
mysql> show create trigger make_hash;
+-----------+----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+
| Trigger | sql_mode | SQL Original Statement | character_set_client | collation_connection | Database Collation |
+-----------+----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+
| make_hash | | CREATE DEFINER=`root`#`localhost` TRIGGER `nntp`.`make_hash`
BEFORE INSERT ON `nntp`.`newsgroups`
FOR EACH ROW
BEGIN
set new.hash = md5(new.newsgroup);
END | utf8 | utf8_general_ci | latin1_swedish_ci |
+-----------+----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+
1 row in set (0.00 sec)
mysql>
mysql> DELIMITER $$
mysql>
mysql> USE `nntp`$$
Database changed
mysql> CREATE
-> TRIGGER `nntp`.`make_hash_update`
-> BEFORE UPDATE ON `nntp`.`newsgroups`
-> FOR EACH ROW
-> BEGIN
-> set new.hash = md5(new.newsgroup);
-> END$$
Query OK, 0 rows affected (0.19 sec)
mysql>
mysql> show triggers;
-> ^CCtrl-C -- exit!
Aborted
thufir#dur:~$