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)
Related
I have a table with the following columns (simplified): openingtime | timezone
This tables holds opening times. The datetime is in the timezone my server is in, timezone is the timezone of the location the opening time is for. I would like to query the datetime column ending up with the local time.
Example data:
2022-07-08 11:00:00 | Europe/London
My server is in Europe/Paris so the expected output would be 2022-07-08 10:00:00
The following only gives my NULL as results:
SELECT CONVERT_TZ(openingtime, 'Europe/Paris', timezone)
FROM openingtimes
To use CONVERT_TZ() you need to install the time-zone tables otherwise MySQL returns NULL.
To load time zone:
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
After time zone loaded:
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.25 |
+-----------+
1 row in set (0.00 sec)
mysql> SELECT CONVERT_TZ('2022-07-08 11:00:00', 'Europe/London','GMT') ;
+----------------------------------------------------------+
| CONVERT_TZ('2022-07-08 11:00:00', 'Europe/London','GMT') |
+----------------------------------------------------------+
| 2022-07-08 10:00:00 |
+----------------------------------------------------------+
1 row in set (0.00 sec)
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.
Server version: 10.1.21-MariaDB-1~jessie
select 'a%b' like '%\%\%';
+--------------------+
| 'a%b' like '%\%\%' |
+--------------------+
| 1 |
+--------------------+
1 row in set (0.00 sec)
the like clause represents 'wildcard + literal % + literal %' but it matches 'a%b'.
or
select 'a%b' like '%\%\%\%\%\%';
+--------------------------+
| 'a%b' like '%\%\%\%\%\%' |
+--------------------------+
| 1 |
+--------------------------+
1 row in set (0.00 sec)
MySQL 5.5.38 returns 0 for both statements. Is the syntax of MariaDB different?
Add
#rahul pointed that the syntax is wrong, so I created a dummy table and ran
SELECT * FROM `table1` where 'a%b' like '%\%\%';
which matches every row in the table.
However, a row with field1='a%b' doesn't match when I ran
SELECT * from `table` where field1 like '%\%\%';
Now going to test on 10.1.22.
It seems this is fixed in 10.1.22.
Server version: 10.1.22-MariaDB-1~xenial mariadb.org binary distribution
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> select 'a%b' like '%\%\%';
+--------------------+
| 'a%b' like '%\%\%' |
+--------------------+
| 0 |
+--------------------+
1 row in set (0.00 sec)
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)
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:~$