天天看點

mysql command建立_使用mysql指令建立mysql資料庫(Create mysql database using mysql command)

使用mysql指令建立mysql資料庫(Create mysql database using mysql command)

我在嘗試使用mysql指令建立資料庫時遇到問題。 我正在使用的代碼是;

using (MySqlConnection con = connect_db())

{

con.Open();

MySqlCommand cmd = new MySqlCommand("CREATE DATABASE @name;", con);

cmd.Parameters.AddWithValue("@name", "fancydb");

try

{

cmd.ExecuteNonQuery();

}

catch (Exception exc)

{

return;

}

cmd.Dispose();

con.Close();

con.Dispose();

}

當我嘗試運作此代碼時,我總是收到錯誤消息,說我有一個

“fancydb”附近的mysql文法錯誤

但是當我把命名放在指令中時: "CREATE DATABASE facnydb;" 有用。 任何人都可以向我解釋為什麼隻有在我嘗試使用參數時才會發生錯誤?

I am having a problem when trying to create a database using mysql command. The code i am using is;

using (MySqlConnection con = connect_db())

{

con.Open();

MySqlCommand cmd = new MySqlCommand("CREATE DATABASE @name;", con);

cmd.Parameters.AddWithValue("@name", "fancydb");

try

{

cmd.ExecuteNonQuery();

}

catch (Exception exc)

{

return;

}

cmd.Dispose();

con.Close();

con.Dispose();

}

When I try to run this code I always get an error saying that I have an

error in mysql syntax near "fancydb"

but when I put the name in the command like: "CREATE DATABASE facnydb;" it works. Can anyone explain to me why is the error only happening when I try and use parameters?

原文:https://stackoverflow.com/questions/16770974

更新時間:2020-01-26 22:01

最滿意答案

create-statement不是資料操作語句。 參數僅允許在此類操作中使用。 create-statement是一個資料定義語句。

The create-statement is not a data-manipulation-statement. Parameters are only allowed in such kind of operations. The create-statement ist a data-definition-statement.

2013-05-27

相關問答

您可能需要更新mysql套接字的路徑。 sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock 我認為這已經在這裡得到了解答: 更新Mac OS X Yosemite後,Mysql無法啟動(Mac OS 10.10) You may need to update your path to the mysql socket. sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock I think this was a

...

mysqladmin -u[username] -p[password] drop [database]

Try the following command: mysqladmin -h[hostname/localhost] -u[username] -p[password] drop [database]

MySQL的文檔說 : CREATE DATABASE建立一個具有給定名稱的資料庫。 要使用此語句,您需要資料庫的CREATE權限。 CREATE SCHEMA是MySQL 5.0.2之前的CREATE DATABASE的同義詞。 是以,這兩個指令也是一樣的。 The documentation of MySQL says : CREATE DATABASE creates a database with the given name. To use this statement, you nee

...

你是以root身份登入的嗎? 浏覽到包含foler的mysql.exe并嘗試在cmd中輸入: mysql.exe -u root --password

RESOLVED:** Thanks to all for your kind replies. I solved that problem. I changed the 'user' table in 'mysql' database by using phpmyadmin and set the fields to 'Y' while tho

...

好的,你在mysql指令中給出了SCHEMA NAME。 是以mysql想要先将模式更改為myDatabase,然後才能這樣做。 沒有架構myDatabase。 删除-D選項,如: mysql -u root -p < backup.sql

ok, you give the SCHEMA NAME in the mysql command. So mysql want to change first the schema to myDatabase AND CANT THAT DO. ther

...

下面解決了我的問題: sudo chown -RL root:mysql /usr/local/mysql sudo chown -RL mysql:mysql /usr/local/mysql/data sudo /usr/local/mysql/support-files/mysql.server start 從這個SO回答 。 Below solved my problem: sudo chown -RL root:mysql /usr/local/mysql sudo chown -RL

...

不,你不能使用cp指令建立任何資料庫。 最簡單的方法是 1-轉儲沒有資料的new_york資料庫。 mysqldump -u${USERNAME} -p --no-data new_york > new_york.sql

2-建立los_angeles,并導入new_york資料庫轉儲。 CREATE DATABASE los_angeles;

use los_angeles;

source new_york.sql;

希望這可以幫助 No you can not create any da

...

不,use database指令沒有很大的成本。 但是如果使用MyISAM,UPDATE語句将鎖定整個表。 您可能會看到多個UPDATE語句互相排隊。 我建議對所有表使用InnoDB。 不僅因為它支援行級鎖定(實際上MVCC比行級鎖定更好),而且InnoDB在抵抗資料損壞方面優于MyISAM。 No, the use database command does not have a great cost. But the UPDATE statement locks the whole table

...

create-statement不是資料操作語句。 參數僅允許在此類操作中使用。 create-statement是一個資料定義語句。 The create-statement is not a data-manipulation-statement. Parameters are only allowed in such kind of operations. The create-statement ist a data-definition-statement.