Tried to create DB with Django by mistake - mysql

So I read somewhere that Django doesn't create the DB in production on MySQL. It only created the tables and you have to create the DB in MySQL before you can do syncdb. However, I made the mistake of doing syncdb when the database with the name in my.cnf didn't exist. And now I'm locked out of mysql. I can't log into it using mysql -u root -p. It gives me error: ERROR 1049 (42000): Unknown database

Figured it out. Just comment out the part specific to the database in which Django tried to create tables (in the file my.cnf). Then you should be able to log into MySQL.

Related

ERROR 1227 (42000) at line 9: Access denied; you need (at least one of) the SUPER privilege(s) for this operation Operation failed with exitcode 1

I tried using the mysql pump to create a backup of my MySQL database. When I tried to restore the backup to another server I am getting the error mentioned in the title. I know that question with this error has been asked before but all answers state that I need to delete the definer clause from the .sql backup file. However, I do not have a definer word at all in my backup file because I backed up my database doing:
mysqlpump --skip-definer -u root -p testempty > c:\users\admin\documents\dumps\backup.sql
I searched trough the backup file and there is absolutely no definers at all.
However, the problem is that I am trying to backup and restore to a different database name and my sql contains database1.tableName syntax. I am trying to restore to database2
That might be the reason for the problem. I know that if I was using mysqldump instead of mysql pump I could do:
mysqldump -u root -p testempty > c:\users\admin\documents\dumps\backup.sql
which exports without database name
but mysqldump does not provide skip definer option :(
Why is it such a nightmare to backup and restore mysql database and so easy to do it in MSSQL database? I am trying to streamline my backup and restore process and there are roadblocks everywhere.
I downloaded the database, edited it with notepad++ and after that I deleted "Definer = your username # local host" and it worked for me.

MySQL says "Table 'database.table' doesn't exist"

I connect my Rails app to MySQL database, working with that and after turning off the laptop and starting Rails and MySQL server again, I get the error
ActionView::Template::Error (Mysql2::Error: Table 'database.table' doesn't exist: SHOW FULL FIELDS FROM `table`):
This is in Rails log.
When I log in into MySQL through the terminal
mysql -u root -p
choose a database and then try to display data from a table, like
mysql> select * from users;
ERROR 1146 (42S02): Table 'database.users' doesn't exist
I google this issue and found a temporarily solution, but this is not appropriate because it involves remove all old data in the respective database:
cd /usr/local/mysql/data
sudo rm -rf database_name
So I would like to ask you for help - how to properly figure out this issue?
Thank you
Looks like you're using rails, did you issue the command
rake db:migrate
And while you're in mysql I suggest you to get the list of available tables with:
show tables;

importing database from phpmyadmin to linode

I've been searching the web for a solution for a while now & just can't seem to get it with what i've found online. I've exported my phpMyAdmin database & uploaded it to my Linode so its now there ( /home/user_name/public/www.sitename.com/public/phpmyadmindatabase.sql )
So now in the terminal i'm entering the following:
mysql -u root -pMyPassword database_name < ~/public/sitename.com/public/phpmyadmindatabase.sql
and I get the following:
ERROR 1049 (42000): Unknown database 'database_name'
Now I'm wondering if i need to create 'database_name' first, but I'm following Linode's own start up guides:
http://library.linode.com/hosting-website#sph_installing-mysql
and they say right at the section "Creating a Database"...(If you already have a database you'd like to import...skip to "importing a database"). So i have been assuming i shouldn't be creating a database since it told me to skip it.
Any & all help would be greatly appreciated...
thanks,
Stupid mistake...just needed to create the new DB manually or make sure phpmyadmin is creating the DB in mysql when its added to the Linode.
On another note - Linode has pretty great customer support (guess that would be the first place to go).

Importing using MySQL WorkBench... error ERROR 1046 (3D000)

Scenario: building a RoR enviroment locally for development. Production is on EngineYard / GitHub. All now working ok, except DB isn't importing.
I have a .sql file that i've taken from my prod EY site. Now i need to import it to my MySQL locally. I'm using Workbench (as i'm new to this), but getting error below.
Please help?
08:07:43 Restoring /home/james/Downloads/Futology.sql Running: mysql
--defaults-extra-file="/tmp/tmpAVeE58/extraparams.cnf" --host=localhost --user=root --port=3306 --default-character-set=utf8 --comments < "/home/james/Downloads/Futology.sql" ERROR 1046 (3D000) at line 22: No database selected
Operation failed with exitcode 1 08:07:43 Import of
/home/james/Downloads/Futology.sql has finished with 1 errors
Workbench doesn't know the database (schema) you want to use.
In workbench, when using Data Import/Restore, just below where you choose the file to import, it asks "Default Schema to be Imported To"
Just choose the database (schema) you want it to use from the dropdown titled Default Target Schema. If you don't have a database (schema) already, you can create it with the "New" button.
This is confusing because MySQL generally seems to use the term database but Workbench uses schema. They mean the same thing for most purposes. MySQL 'create schema' and 'create database' - Is there any difference
Not used Workbench too much however it's easy enough to do from command line have a look at this (below phpMyAdmin instructions)
The command you're after is:
mysql -u #username# -p #database# < #dump_file#
Simply by choosing your target schema
As I circled in above image
Similar to brynn's answer, simply modify your SQL file and insert the following line at the very top:
use yourdatabasename
Replacing yourdatabasename with the database into which you are trying to import. Also, this database should already be created (albeit empty) before you import into it.
Here's another option that worked for me. I'm using MySQL 5.5 on a VM I set up for importing a large MySQL .sql dump that contained: 1). a create table statement 2). insert statements for inserting a large amount of data into the table.
at the MySQL command line client prompt type:
use yourdatabasename
source d:\yourpath\yourfilename.sql
for more info on the 'source' and other commands, enter ? at the prompt.
The above command line is correct. I found I have to do this when importing .sql files from older versions of MySQL. I also found I had to edit the .sql file (top of the file) and set the db name to be the same as the blank db you create before doing the import.

Get database hosted on MySQL server

Im trying to create my own database with MySQL Workbench and run some queries on it. I have MySQL server 5.1 running and can enter queries in the command line tool to ask for version number and such.
But how do I get the server to host the database that I created in Workbench? When I enter "use MijnDatabase" or "-u root#localhost -p MijnDatabase" it says the database cannot be found. This makes sense, "MijnDatabase" the database file name and it's not connected to the server in any way (also tried with "mydb" wich is the db name I see inside Workbench).
Anyway I'm missing the link between MySQL server and hosting an actual database file.
When you create a database use only lower case letters and use underscore to separate words:
create database my_database;
use my_database;
show tables;
etc...
To connect to your database use:
mysql -u root -p
enter your password then
use my_database;
show tables;
etc...
I have not used MySQL Workbench but the command line and phpMyAdmin. I suggest you start using the command line to learn a little bit MySQL, then use a GUI tool. However the command line is your best teacher.
Have a look in the reference doc: http://dev.mysql.com/doc/refman/5.1/en/create-database.html
. Lean how to create a user and grant him permission on the database.