I am unable to delete a database in mysql ending in pound '#' - mysql

I created a database xyz# in MySQL accidentally when I was trying to create xyz. Now when I try to drop it, I get to the next line. I searched online but no luck. I tried escape characters / \ and single and double quote to consider # name of the database but no luck.
Any idea how to delete a database ending with #. Thanks

Use backticks:
DROP DATABASE `dbnameendingin#`

Related

Replace instances of newlines in entire database

In MySQL Workbench I want to replace all instances of newlines with the explicit string "\\n" in my entire database, except where the string already exists. How would I form the query? Thanks.
[edit]
It just occurred to me that it might be easier to dump the database and use Notepad++ to replace the strings. But I was hoping there were a way to do this from within MySQL Workbench itself.
You will need to do this for each table and each column that you want to do the replacement. For example:
update table set column = REPLACE(column,'\n','\\n')

mysql command line escape - sign

I am trying to create a database but I can not figure out how to escape the - sign in the database name.
mysql> create database happy-face;
gives me an error
mysql> create database happyface;
works without problems
How can I escape the - sign in the name of the database ?
You could quote the name with backticks
mysql> create database `happy-face`;
but you might want to avoid names that require backticks since it makes your life a little more complicated.

Deleting mysql db syntax?

Im trying to tidy up my local dbs which are left over duplicates and dev dbs from past projects.
To do it im viewing in Sequel pro, then im deleting them using the command DROP DATABASE testdatabase; that works fine.
But some of my dbs have names like lorem-blog-db (with dashes) when i try to run DROP DATABASE lorem-blog-db; it gives me back an error near 'lorem-blog-db'.
Any idea how to resolve this ? i guess its to do with the dashes.
In MySQL, you can use backticks to escape names. Like so:
DROP DATABASE `my-least-favorite-db`

MySQL delete trailing question marks

I imported data from csv files into a MySQL database, but made the mistake of not
removing the trailing spaces in the csv columns. So the spaces are seen as '?' at
the end of some values in the database (of type Varchar). I want to get rid of these.
Can I somehow delete all these ?s in the database in one go? I know of the replace
command, but I think that works on a single column of a singe table at a time, which will
be very time consuming for me. Could anyone please suggest something better? Thanks!
You can use the trim function
UPDATE table SET column = TRIM(TRAILING '?' FROM column)

Does MySQL allows to create database with dot?

Does MySQL allows to create database which has dot (.) in its name?
I'm using MySQL 5.1.22.
You can't use the dot in a database name. Also, I'd avoid using it in any identifier. A common convention is to use underscore instead. It will serve the same purpose and will avoid a LOT of confusion. If you do have a good reason for using strange and otherwise-illegal characters in a table or field name, then you have to escape it.
to escape identifiers in MySQL, use the backtick:
SELECT `select`, `some.field name`, `crazy()naming+here`
FROM `my-=+table`
Getting into the habit of backticking all field names regardless of whether you need to is a good practice in my opinion, but that's another story.
You can use . in names from MySQL 5.1.6 according to the documentation.
However, as has been said and will said again, please don't do it. For every problem you think you're solving now you'll be creating five which will bite you later on. Since . is used to qualify names - e.g. database.table or table.column you'll have to quote your database name every time you use it.*
You can do this with backticks:
CREATE TABLE `do.not.do.this` (col INT);
or using double quotes if you set the following option:
SET sql_mode='ANSI_QUOTES';
CREATE TABLE "asking.for.problems" (col INT);
* Not strictly true - you have to quote any character that's not alphanumeric or _ or $ , but . is a particularly troublesome option to have in your names.
Before MySQL 5.1.6, database and table names cannot contain /, \, ., or characters that are not allowed in file names (see 8.2. Schema Object Names).
In versions after 5.1.6 you have to quote your tablename with a backtick (`) - but as others also advised: you shouldn't do this to prevent any unnecessary trouble.
MySQL 5.0.22 doesn't appear to allow it:
% mysqladmin -uroot -pXXX create foo.bar
mysqladmin: CREATE DATABASE failed; error: 'Incorrect database name 'foo.bar''
Even it if it did allow it, I would strongly recommend against it.
At the very least you'd have to escape any reference to that database with backticks in every single query that ever uses it.