workaround: make mysql column name longer than 64 chars - mysql

I am working on an application to dynamically generate mysql tables from Excel files.
Current I am stuck because some of the column names in the Excel files have more than 64 characters, while in mysql the maximum length for column names are 64 characters.
I thought about setting up another table to store the column names but then I will have to perform some joint operation to retrieve them.
Is there any clever way to workaround this problem?

MySQL is an open source project. You can download the source code, change things, and build your own version.
I haven't read MySQL source, but the odds are good that the maximum length of identifiers is a compile-time constant. It might be as simple as finding that constant, changing it, and recompiling. (Simple doesn't necessarily mean easy, though.)
It really is pretty easy in PostgreSQL. The PostgreSQL docs even tell you the name of the constant, and which file it's in. (NAMEDATALEN, in src/include/pg_config_manual.h)
Personally, I think you're better off fixing the Excel column names to conform to MySQL limits.

There is no other way to increase the length of the column size more than 64. here are some standards. you cant go beyond this limit.
Identifier Maximum Length (characters)
Database 64
Table 64
Column 64
Index 64
Constraint 64
Stored Program 64
View 64
Alias 256
Compound Statement Label 16
And you cant retrive the column names through join operation. through join operation you can only achieve data of 2 or more tables. the solutio to your problem is that you should truncate the column names in excel already before exporting them to mysql.

Related

Converting varbinary to longblob in MySQL

We are storing data in an Innodb table having varbinary column. However, our data size requirement has grown to over 1 MB and hence I converted the column to longblob.
alter table mytable modify column d longblob;
Everything seems to be working as expected after I converted the column. However, I like to know from people who have done it earlier if anything more is required other than just converting column as shown above, especially
is there any MySQL / MariaDB version specific issues with longblob that I should take care of. There is no index on the column.
We use mysqldump to take regular backup. Do we need to change anything since the blob storage mechanism seems to be different than varbinary.
Any other precautions/suggestion.
Thank you for your guidance

maximum character size that a mysql query can handle

I am trying to run this query but there are no values being retrieved , I tried to find out the length of characters till which values are returned. Length was 76 characters.
Any suggestions?
SELECT tokenid FROM tokeninfo where tokenNumber = 'tUyXl/Z2Kpua1AvIjcY5tMG+KlEhnt+V/YfnszF5m1+q8ngYvw%L3ZKrq2Kmtz5B8z7fH5BGQXTWAoqFNY8buAhTzjyLFUS64juuvVVzI7Af5UAVOj79JcjKgdNV4KncdcqaijPQAmy9fP1w9ITj7NA==%';
The problem is not the length of the characters you select, but in the characters, which are stored in database field itself. Check the tokenNumber field in your database schema - if it is varchar, or blob or whatever type, what is the length, etc...
You can insert/select pretty much more than 76 characters in any database, but you can get less that 76, as in your case, it depend on how you handle the field they are stored in.
A quick way to see the tokeninfo table properties is to run this query:
SHOW COLUMNS FROM tokeninfo;
If the data types differ from what you expect them to be based on a CREATE TABLE statement, note that MySQL sometimes changes data types when you create or alter a table. The conditions under which this occurs are described in Section 13.1.10.3, Silent Column Specification Changes.
the max size would be limited by the variable max_allowed_packet
so, if you do a
show variables like 'max_allowed_packet'
it will show you the limit. By default, it is set to
1047552 bytes.
If you want to increase that, add a line to the server's
my.cnf file, in the [mysqld] section :
set-variable = max_allowed_packet=2M
and restart mysql server.

Compress text in SQL

I got a multi-use SQL table in my SQL Server 2008 database. It can store only 100 characters as value.
Now I want to store a value in it that has more than 100 characters. Is it possible to zip or compress a text with SQL Server functionality?
If your column is defined as VARCHAR(100), it can hold a maximum of 100 characters. There's no "magic" or "compression" that makes this go away.
Yes, SQL Server has text compression - to reduce the disk space used. But if the column is limited to 100 characters, it can store no more than 100 characters.
If you need more - you need to define a column with a larger capacity. There's no other solution.
It's very easy to change a column's datatype, too - so if you need to, you should be able to just issue a SQL statement like:
ALTER TABLE dbo.YourTable ALTER COLUMN YourColumn VARCHAR(150)
and now your column can store up to 150 characters. This is a non-destructive change, e.g. existing data will not be affected (not wiped out or deleted).

perl,mysql table name limit?

i am interacting with the mysql database via perl. I was wondering if there are table name limits.
Also. How do i handle special characters within the table names when creating it through perl?
thanks
According to the MySQL docs, the maximum length for a table name is 64 characters. This page also describes the permissible syntax for identifiers.

mysql table name length limit? - please test on default mysql (asked in 2010 for mysql <5.5)

Does vanilla MySQL have a table name length limit?
(I've tested to 100 chrs on my modified MySQL - no limit so far.. I don't have vanilla MySQL accessible readily, though, but I wonder if my dynamically-created table schema will run on default MySQL)
Question: What happens if you go over 64 chrs on default MySQL? Can you test this please and paste MySQL error or results if any?
n.b. usage scenario where per user would never select another user's dataset.
Here're the limits
Database: 64
Table: 64
Column: 64
Index: 64
Constraint: 64
Stored Function or Procedure: 64
Trigger: 64
View: 64
Compound Statement Label: 16
http://dev.mysql.com/doc/refman/5.0/en/identifiers.html
The question is based on wrong assumptions.
There shouldn't be a direct answer.
It is duty of every fellow SOer to warn the OP against wrong decision. Instead of helping him wrong way to get your rep points.
Always avoid dynamically-created table schemas. Database schema is not the thing that should be dynamic. The data in the tables - yes. but not tables itself
Note that you are using a relational database. And while it is as simple as an egg to make a relation based on the field value, at the same time it's impossible based on table names.
Therefore, there shouldn't be dynamically created tables and data splitting. Use one table for similar data. That's one of most basic database rules.
I think it's 64 characters. At least that's the limit on my setup.
Attempted with 133 characters:
mysql> create table aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ( id INT );
ERROR 1103 (42000): Incorrect table name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
For me, it failed at 54 characters. I am using MySQL behind Django 1.4.5.
Server version: 5.5.40-0ubuntu0.14.04.1 (Ubuntu)