This question already has answers here:
Selecting a database in mysql with spaces in its name
(6 answers)
Closed 3 years ago.
I just signed in to MySQL and am trying to connect to a database so that I can begin to write tables. My research understanding is that you use "use" followed by the database name, and end with ;
The database name that I am trying to connect to is 3 words with space in between them (i.e., A B Database)
When I try use A B Database; it says there is a syntax error at the B. Any reasons why this may be happening?
Surround the database name with back-ticks:
e.g.
create database `abc de f`;
use `abc de f`;
The back-tick character is used to surround database, table or field names that contains a space.
Related
This question already has answers here:
How to determine which database is selected
(5 answers)
Closed 2 years ago.
You may use USE statement
USE <db_name>
to use the named database as the default
but how to get the name of the database that is currently used?
So if USE sets the db name, is there a kind of GET or SELECT statement to read database that was set as the default?
Suppose you get a result of a query after many hours and you forgot what particular database that query was targeting. It would be helpful to be able to ask for the default database name to know which database that query result refers to.
You can just do:
select database()
This question already has answers here:
How do I rename a MySQL database (change schema name)?
(46 answers)
Closed 3 years ago.
I created a database with the name of old. Now I need to change database name to new.
But,I did not know how to change a name?
I believe that the ability to rename a database has been removed from the spec for security reasons. What you will need to do is create a full dump of the database "old". Then you'll need to create a new database and re-import the data
This question already has an answer here:
MySQL schema name with dash does not allow me to execute command line query
(1 answer)
Closed 5 years ago.
When I write this code it is not working.
CREATE DATABASE blabla-bla;
You can use punctuation, whitespace, and so on in SQL by using delimited identifiers. Read https://dev.mysql.com/doc/refman/5.7/en/identifiers.html for more information on this.
MySQL delimited identifiers are back-ticks by default.
CREATE DATABASE `blabla-bla`;
As #JohnConde commented, it's easier to use SQL if you avoid cases when you need to use delimited identifiers.
This question already has answers here:
Are table names in MySQL case sensitive?
(5 answers)
Closed 5 years ago.
Is there a way to ignore database (not table or column) name case in mysql? I have database FOO but I'd like to refer to it as foo.some_table or FOO.some_table. Setting lower_case_table_names doesn't seem to work. I've even migrated to a new database and recreated the database with name foo but now FOO.some_table doesn't work. Is this possible?
You can find the answer to your question here: link. It's article in MySQL documentary about identifier case sensitivity.
This question already has answers here:
Are table names in MySQL case sensitive?
(5 answers)
Closed 6 years ago.
I would like to be able to query the table Users and its columns UserName and Email case insensitively:
select username, email from users;
I know MySQL is case-insensitive for strings by default--that is not my question. I would like to query case-insensitive table and column names.
The SQL Server environment I work allows me to do so but don't know how to do so in MySQL.
You can use the lower_case_table_names system variable as described in Documentation. You can set this variable to the allowed value on start of mysqld or even in my.cnf config file