How do I access my MySQL DB through command line? - mysql

So I'm working on this Django project, with MySQL as DB engine. I made some sort of mistake, and now I have to drop a table I accidentally created. So I'm trying to access the DB through command line, but cannot figure out how.
Could anyone help? Or is there a better way of dropping a table in MySQL DB?Thanks in advance.

Use the dbshell command
python manage.py dbshell
then while in the shell, depending on what database you are using, you type the command to show tables to identify the table you want to drop.
still in the shell, you can use SQL command to drop the table
DROP TABLE shop_brand;
source => How can i delete database table in django?

You can use python manage.py dbshell.

Related

Why do all my procedures run when I import mysqldump file?

I execute the following statement from the cmd terminal to import my MySQL Database:
mysql u- root p- database < "C:\Users\Tom\data.sql"
When I open my MySQL Database from the MySQL Workbench I've realised that more tables have been created that I don't recognise. Basically, what is happening is the stored procedures/routines I have created seem to be automatically running and thus creating many more tables? I don't want this, I'd rather execute routines as I wish using the "Call" statements in MySQL, is there a way stop this happening?

How to run a specific migration of an accidentally dropped table

I accidentally dropped a table using the mysql command line. Luckily the table was empty.
But I need this table back. So I would like to re-run only the migration for that table, and not for other tables since these are still present.
When I run knex migrate:latest, it returns "Already up to date". The same if I npm run migrate name-of-specific-miration-file.
I use knex. How can I run only the specific migration file I want it to run?
I got it to work doing the following:
On MySql command line: create table my_table_name (hello text);
In terminal: knex migrate:down name_of_migration_file.js
In terminal: knex migrate:up name_of_migration_file.js

Importing sql dump file into PHPMyAdmin

Here is what I am dealing with, and I apologize for not being very sure of what I am doing.
I am trying to import a sql database dump file into xampp so that I can run a friends application.
I cloned the repository and put the code base into my htdocs folder. However, it needs to communicate with the database to run.
I have the dump file however when I go to import it I get the following:
Error
SQL query:
DROP TABLE IF EXISTS `sl_address`
MySQL said: Documentation
#1046 - No database selected
Do I need to create a database to dump into before I import the sql dump file? If so, does it matter what I name it, if it does how do I know what to name it?
I imagine if I don't name it correctly that the application won't be able to communicate with it.
I am really new to all this so I appreciate any help I can get. Thank you!
I think you need to create a database and select it before you run the SQL script that was generated by the dump.
Something like this:
create database newdb;
use newdb;
then the rest of your script.
Bobby

When I try to log into MySQL via command line, keeps saying "unknown database 'magento2'"

When I try to log into MySQL via command line, keeps saying "unknown database 'magento2'"
Any ideas why? Tried as my username and root, getting the same message. If I can't log into mysql, how could I create a database to begin with of that name? So confused.
You should separate between your database application and a logical database. MySQL server is your database application / server.
When you're logging on to MySQL, you're choosing which logical database you would like to work with. A logical database is actually a container of objects such as tables, triggers, views, etc.
So when you see the error unknown database X, it's because you installed the MySQL server, but didn't create the logical database.
To see a list of all logical databases in your server, login to MySQL and run the command show databases;
To create your database, run the command create database magento2;
Now when you login to that database, it should be there and you can start creating your tables and query data from them.
I had the same issue and found that the database name was set in a cnf file. Perhaps you have something similar.

Creating Database using phpMyAdmin in WAMP

I've installed WAMP stack and tried creating databases using phpMyAdmin. But in the Databases section it says 'No Privileges' which means that I have no rights to create database. However it seems possible for me to create, drop data bases using command line. Even when I create a database using command line it's not displayed in phpMyAdmin too.
Also I couldn't create database, tables using php also. Please help me out on this.