MySQL select from UPPER CASE table - mysql

I have a legacy application and am trying to move the MySQL server to a Unix based system (from windows).
My tables are stored as lowercase in MySQL but some of the queries from the application are “select * from UPPERCASE”. This gives me a table does not exist error. I’ve tried making lower_case_table_names=1 and that was not successful.
Is it possible to query with an UPPERCASE table name in MySQL 5.7?

Related

Is it possible to make the insert command from existing table data

I have table which has a few data.
name score
1 AAA 100
2 BBB 98
3 CCC 85
Now I want to make the insert sentence such as
insert into pepolescore(name,score) VALUE("CCC",85)
automatically.
Is there any command to do this or any function ? by mysql commandline or phpmyadmin.
MySQL queries can address another schema on the same MySQL Server instance by using qualified table names. See https://dev.mysql.com/doc/refman/8.0/en/identifier-qualifiers.html
But this does not work if the tables are on separate MySQL Servers. A given SQL query can only address schemas on the same server.
Here are a few workarounds:
Use mysqldump to export data from one table and then use mysql to import it to the other table on the other instance. You need to be careful not to let mysqldump output the DROP TABLE command, so read about the options here: https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html
MySQL supports a table engine called FEDERATED, where a table can function as a sort of proxy to a table on another MySQL Server. Then you can use INSERT ... SELECT syntax as if the tables were co-located on the same MySQL Server. The Federated engine has limitations, so read https://dev.mysql.com/doc/refman/8.0/en/federated-storage-engine.html and its subsections to learn more.
Use a community tool such as pt-archiver to copy data from one MySQL instance to the other. Read the manual to learn more: https://docs.percona.com/percona-toolkit/pt-archiver.html
Write your own custom code in a client application. Create two connections, one for each MySQL Server. Fetch query results from the first server, and store the resulting rows in variables in your application. Then use these rows as the tuples to insert using the second connection to the other MySQL Server. This involves writing more code, but you get a lot of flexibility.

What is the cause for the MySQL error FUNCTION doesn't exist? It happens randomly. The server has a high number of databases on it like 900

It is a web application connecting to a MySQL 5.6 server in Amazon. The application using PHP code or Java gets randomly the error FUNCTION getSetting does not exist. It is basically doing a query like select getSetting('a_setting_name'); or while used from the stored procedures.
In order to avoid the error some stored procedures were changed to not using the function and get the value by doing a raw select to the table. Also many not used databases were deleted.
If the function is defined in a different database than the one you've selected as the default, you need to qualify the function name with the database name, just as you would if you wanted to access a table or view in a different DB.
SELECT otherDB.getSetting('a_setting_name');

MySql - Two tables with different casing

I would like to create two tables:
mytable
MyTable
I am using Navicat to create those tables. The problem is, I can't create both because after one has been created, it says that the database already exists.
I checked on StackOverflow and find each times people speaking about set up lower_case_table_names = 2 and restart MySQL server but still the issues is firing.
I've tested on a MySQL Linux server and it works properly...
Do you have any idea ?
Thanks!

MySQL: Convert Date column to Year column

I have a table with DATE column. All the dates are valid i.e. no 0000-00-00. But we were in fact using only the year part of these dates. I tried changing the type of this column to YEAR(4), I found following scenarios:
On my local system, MySQL version 5.5.37 via MySQL CLI, changing type retains the year.
On my local system, MySQL version 5.5.37 via Adminer, changing type retains the year.
Our internal DB server, MySQL version 5.0.46 via MySQL CLI, changing type retains the year.
Our internal DB server, MySQL version 5.0.46 via PhpMyAdmin, changing type retains the year.
Staging DB server, MySQL version 5.6.13 via PhpMyAdmin, dates in columns get converted to 0000.
Staging DB server, MySQL version 5.6.13 via MySQL CLI, dates in columns get converted to 0000.
What could cause these issues and how can I solve this? Currently we created a Rake task where we first create an additional column, copy existing column dates to new one, alter the column and copy just years back.
Edit: http://dev.mysql.com/doc/refman/5.6/en/upgrading-from-previous-series.html
Try this
ALTER TABLE `tablename`
CHANGE `columnName` `columnName` YEAR
This returns you 0000 in phpmyadmin. You should create a new column and rename it and then delete the old one.
The YEAR(2) data type has certain issues that you should consider before choosing to use it.
As of MySQL 5.6.6, YEAR(2) is deprecated.
YEAR(2) columns in existing tables are treated as before, but YEAR(2) in new or altered tables are converted to YEAR(4).
Read more here:
http://dev.mysql.com/doc/relnotes/mysql/5.6/en/news-5-6-13.html

How to get all the queries which we have used in a mysqldb

I have a mysql database with lots of tables and records in it. I want to get the list of queries which were used to create tables , insert records etc in that mysqldb. Is it possible. I have seen it in Oracle sql developer. If we click on the table we can view the queries which we have used, for DDL. How to do that in msyql. I am using mysql command line client.
You could use the mysqldump-utility for that
In Linux:
mysqldump my_database_name >dumpfile.sql