I cannot run source table_name.sql
when I try, I get the following error:
ERROR:
Failed to open file 'cars.sql', error: 2
I have been following zeetcode:
http://zetcode.com/databases/mysqltutorial/introduction/#mysql
http://zetcode.com/databases/mysqltutorial/firststeps/
The first provides a list of commands to create a database called mydb and a set of tables to be used in the tutorial including one named Cars.
The second link shows you how to access the databases (SHOW DATABASES;) which I could do but when I go to the previously created database mydb, I can see the previously created tables including Cars (even though the tutorial says I should not see anything.
when I follow the next command: source cars.sql, I receive the error above
yet, this query works:
mysql> SELECT * FROM Cars;
any ideas as to why the source function would not work?
This is the first time I am working with mysql.
where is the file cars.sql located? you may need to specify the full path to the file in order for it to be located by mysql.
Related
In codeAnywhere I'm trying to run pre written script files to create a table. When using codeAnywhere one must import the file to the shell for the code first, as I have done. However I have been unable to use the SOURCE command to run these files. I have currently attempted this syntax:
USE exams SOURCE students.txt;
What is the correct syntax here? Do I need to name the database in the syntax?
Are there other commands which run text files containing code?
EDIT: I tried using this syntax, to the following result:
ERROR: Failed to open file 'exams(question5.txt)', error: 2
Put the commands on separate lines, without semi-colons for the shell commands, and if this doesn't work, then prefix with \ as well (I don't need to on my setup, but it's in the docs):
USE exams
SOURCE students.txt
https://dev.mysql.com/doc/mysql-shell-excerpt/5.7/en/mysql-shell-commands.html
On the shell you can use the following command to execute the queries from a text file:
mysql db_name < text_file
Hint: If the USE command (with correct database name) is specified on the textfile you don't need to specify the database. The SOURCE command is not available on MySQL instead you need the <.
You can find more information about executing queries from text files here:
https://dev.mysql.com/doc/refman/5.7/en/mysql-batch-commands.html
user inside the plugable DB(PDB21) username -'JEWBDEV' and
PWD-abc123, i am not able to export backup .dmp file please suggest
steps.
Create datapump directory and grant permissions to user
SQL> CREATE or REPLACE DIRECTORY dpump_dir as '/home/user1/dumpfiles';
SQL> GRANT READ, WRITE ON DIRECTORY dpump_dir TO JEWBDEV;
Set the environment (outside sqlplus):
setenv DATA_PUMP_DIR DPUMP_DIR
Export table (outside sqlplus):
expdp JEWBDEV/abc123#pdb21 tables=TABLE1 dumpfile=table1.dmp logfile=jewbdev_exp.log
Note, in above examples some of the values like TABLE1, /home/user1/dumpfiles are written for example, it needs to be changed according to your requirement.
Export everything under a schema/user (outside sqlplus):
To export everything under a user you can skip giving the tablenames, following is the format:
expdp system/manager#<pluggable_database> file=<user>.dmp owner=<user>
Example:
expdp system/manager#pdb21 file=JEWBDEV.dmp owner=JEWBDEV
Also, check this SO question to get better understanding on expdp.
Working example
Following steps are verified at my end:
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 CDB1_PDB1 READ WRITE NO
SQL> alter session set container=cdb1_pdb1;
Session altered.
SQL> CREATE or REPLACE DIRECTORY dpump_dir as '$T_WORK';
Directory created.
Following should be run outside sqlplus:
expdp system/manager#cdb1_pdb1 file=scott.dmp owner=SCOTT
In your case it will be:
expdp system/manager#cdb1_pdb21 file=JEWBDEV.dmp owner=JEWBDEV
So, make sure your pdb name is CDB1_PDB21 when you query show pdbs. If the PDB name is PDB21 then the connect string should change like the following:
expdp system/manager#pdb21 file=JEWBDEV.dmp owner=JEWBDEV
Also, note that we are exporting the user/schema JEWBDEV with SYSTEM user.
I'm having a really hard time believing this question has never been asked before, it MUST be! I'm working on a batch file that needs to run some sql commands. All tutorials explaining this DO NOT WORK (referring to this link:Pass parameters to sql script that someone will undoubtedly mention)! I've tried other posts on this site verbatim and still nothing is working.
The way I see it, there are two ways I can approach this:
1. Either figure out how to call my basic MYSQL script and specify a parameter or..
2. Find an equivalent "USE ;" command that works in batch
My Batch file so far:
:START
#ECHO off
:Set_User
set usrCode = 0
mysql -u root SET #usrCode = '0'; \. caller.sql
Simply put, I want to pass 'usrCode' to my MYSQL script 'caller.sql' which looks like this:
USE `my_db`;
CALL collect_mismatch(#usrCode);
I know that procedures are a whole other topic to get into, but assume that the procedure is working just fine. I just can't get my parameter from Batch to MYSQL.
Ideally I would like to have the 'USE' & 'CALL' commands in my Batch file, but I can't find anything that let's me select a database in Batch before CALLing my procedure. That's when I tried the above link which boasts a simple command line entry and you're off to the races, but it isn't the case.
Any help would be greatly appreciated.
This will work;
echo SET #usrCode = '0'; > params.sql
type params.sql caller.sql | mysql -u root dbname
You might read this question every day so i tried another Stackoverflow's answer before asking:
CakePHP table is missing even when it exists
Anyways. The table i try to select data from does exist (quadra-checked uppercase/lowercase!) and it gets also listed via $db->->listSources().
Here's a screenshot of the query, the message and the last result from listing all Datasource's tables:
http://i.stack.imgur.com/CdhcV.png
Note: If i run this query in PHPMyAdmin manually it works fine. I would say its impossible to get the pictures output at one time in a view - now its up to you to tell me the opposite. By the way: I am pretty sure to use the correct Datasource.
I should tell additionally that the mysql-server is hosted on another platform. Since i can use it for my localhost-phpmyadmin if i modify the config.inc.php i can promise it is no Firewall-Problem.
Written in behalf of xcy7e:
The mistake was to execute the Query from the local Model. Here's the code:
$conn = ConnectionManager::getDataSource('myDB');
$conn->query($query);
// instead of $this->query($query);
hi there i made track star application and everything works fine except for one issue that i face error
CDbCommand failed to execute the SQL statement: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'devnmark_root.AuthAssignment' doesn't exist. The SQL statement executed was: SELECT *
FROM 'AuthAssignment'
WHERE userid=:userid
now this was automatically generated by Yii when i checked for if(Yii::app()->user->checkAccess('createUser',array('project'=>$model)))
18 {
19 $this->menu[] = array('label'=>'Add User To Project','url'=>array('adduser', 'id'=>$model->id));
20 }
then i went to phpmyadmin and executed this query manually
SELECT * FROMAuthAssignmentWHERE userid=4 and there is error which says same that table does not exist.
if i use small case letter for table name then no error.
i executed same query on local wamp 's phpmyadmin same query does not show any error there so this is clear that there is error with my sql .any idea what can i do to solve?
I suggest you hitting up SQL_MODE documentation for setting your final options. http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
For testing you can just do a:
SET sql_mode = '';
Or adjust your command line:
--sql-mode=""
You may try to set the system variable *lower_case_table_names* to 1.
My local application was developed under Windows, howerver production is under Linux and I caused the same problem.
For me it happened because of case sensitivity - table AuthAssignment in database was actually authassignment.
I have found two options to solve it:
rename database table from authassignment to AuthAssignment
or
edit config file component section:
'components'=>array(
...
'user'=>array(...
),
'authManager'=>array(
...
'assignmentTable'=>'authassignment' //THIS LINE SOLVED MY PROBLEM
),
I had the same problem of non-existent authassignment table, I had forgotten running the rights installation which in my case was by following URL i.e.
/index.php/rights/install
and then the setup was like a breeze and self explanatory :)
For me this answer helped the most: original source.
In the authManager in config/main.php you can add lowercased names of the tables like this:
'components'=>array(
'authManager'=>array(
'defaultRoles'=>array('guest'),
'class'=>'RDbAuthManager',
'assignmentTable'=>'authassignment',
'itemTable'=>'authitem',
'rightsTable'=>'rights',
'itemChildTable'=>'authitemchild',
),