I'm wondering if a database name can start with a number e.g 143doors.
I found some answer here http://markmail.org/message/yw57rt3tweldtxet but I'm not quite sure since it's 1999.
Will there be disadvantages if I start with a number?
Within MySQL Workbench, you are going to have trouble querying if you do something like {db_name}.{table} and your db_name starts with a number.
The solution to this is the backtick mentioned in the accepted answer. An example is like:
select * from `2013e93`.blurb
where the db_name is 2013e93 and the table is blurb.
A quick test says, yes you can. Using spaces in database names will lead to trouble, though. You'll have to use `143 doors` (with the backtick) if you really want to do this.
Related
I have a table name that starts with an underscore does that give any special status to the table?
I am asking because the table does not seem to be taken by the replication in some instances. In the MySQL Query Browser it is also impossible to use the "Edit" feature on that table but it is on all the other tables.
We are using MySQL 5.0.37
Cheers,
No, it does nothing special ^^
I'd like to write a query to find a string wherever it exists.
Something that would work like:
foreach(table in database) {
foreach(column in table) {
// in the end, i need to know, which columns in
// which tables that string appears.
}
}
Is this possible?
May I ask why? Honestly, unless it is something you need to do at runtime, I would use mysqldump and use a text editor to do the search.
If you have to do this at runtime, you are going to have to build something dynamically. You can use "show tables" to get a list of tables. You can then use show columns for each of those tables. You'd then need to do some sort of select statement on each column looking for your text (using locate, or using like for example).
This is going to be a really slow process to run at real-time on a server...
yes, this is possible. But I don't think you can do it in pure SQL; you'd better do it in some script languages, like PHP, or shell scripts.
I dare to say, this is impossible with (current) MySQL, as metadata (such as column names) and data (such as the field values) cannot be part of the same query.
Especially
SELECT Field from (DESCRIBE <tablename>)
will error out, as will
SELECT Field from (SHOW FIELDS FROM <tablename>)
as will
DECLARE flds CURSOR FOR DESCRIBE <tablename>
in a stored procedure.
This is to say it is impossible INSIDE MYSQL - it is trivial in PHP and freinds.
Is there any way to later output the name of the database that is currently selected?
Just use mysql_query (or mysqli_query, even better, or use PDO, best of all) with:
SELECT DATABASE();
Addendum:
There is much discussion over whether or not FROM DUAL should be included in this or not. On a technical level, it is a holdover from Oracle and can safely be removed. If you are inclined, you can use it as follows:
SELECT DATABASE() FROM DUAL;
That said, it is perhaps important to note, that while FROM DUAL does not actually do anything, it is valid MySQL syntax. From a strict perspective, including braces in a single line conditional in JavaScript also does not do anything, but it is still a valid practice.
SELECT DATABASE();
p.s. I didn't want to take the liberty of modifying #cwallenpoole's answer to reflect the fact that this is a MySQL question and not an Oracle question and doesn't need DUAL.
You can always use STATUS command to get to know Current database & Current User
slightly off-topic (using the CLI instead of PHP), but still worth knowing:
You can set the prompt to display the default database by using any of the following
mysql --prompt='\d> '
export MYSQL_PS1='\d> '
or once inside
prompt \d>\_
\R \d>\_
Another way for filtering the database with specific word.
SHOW DATABASES WHERE `Database` LIKE '<yourDatabasePrefixHere>%'
or
SHOW DATABASES LIKE '<yourDatabasePrefixHere>%';
Example:
SHOW DATABASES WHERE `Database` LIKE 'foobar%'
foobar_animal
foobar_humans_gender
foobar_objects
Wonder if anyone can help.
I recently had an issue with UTF8 in the Database and pages of a bespoke CMS I inherited. Going forward that's all sorted now, the code and DB has been changed to cater and properly convert, however I have an issue in that existing entries in the DB are obvioulsy sat there in the old character format and I need to convert all those.
Eg Ķ, ī
I was going to run an replace in the mysql DB to replace all these, but what I could do with is knowing what all these weird characters translate to eg ó.
Can anyone recommend a good table/reference to look at ? I have been searching but can't seem to come up with the right thing.
If I understand right these are two byte UTF8 characters.
Thanks
Try running these values in utf8_decode.
It looks like they've been valid, then utf8_encode'd.
If that's the case, try running a loop and update these rows.
I have a DB called:
MY_XXXX and MY_YYYY.
When I go to the phpMyAdmin, it shows in the tree structure...like this:
So, my questions is, is the MySQL or the phpMyAdmin do this things for me...? Is this have some special meaning for that? Thank you.
This is phpMyAdmin making a (sort of reasonable-ish, a bit, actually largely un-warranted) assumption about a naming convention - it's nothing to do with MySQL.
If your looking for more information on such things - see the MySQL Schema Object Names documentation. (As you'll see - it defines no special meaning to the underscore other than stating that it's considered a valid character.)
THis means you have multiple databases starting with MY .
So rather then showing showing it in different headings as MY_1, MY_2 phpMyAdmin shows them as
MY_
1
2
etc.