I've downloaded sample database, which is currently in my Downloads folder. How to connect it with MySQL console so I could test some queries?
Every tutorial I've seen so far is about how to make your own database and then test queries.
I assume you are talking about the "employees" sample?
That is a (zipped) SQL file, which you can load into MySQL by running
mysql < employees.sql
After unzipping. Eventully you also have to provide -u root as username and -p so it asks for a password.
If you use a GUI like MySQL WorkBench it has a menu entry to import SQL scripts.
See also https://dev.mysql.com/doc/employee/en/employees-installation.html and
https://dev.mysql.com/doc/refman/8.0/en/mysql.html
Related
Non-coder here, please advise as newbie. I have a MySQL DB on my ISP's server that provides data for a web site. I want to set up a db on my localhost that I can use for local development. The DBs don't need to be linked, nor do they need to remain synchronized. I just need to start with a current copy of the ISP version.
I have used PHPMyAdmin on ISP to download what I think is a dump file. the file, [mydbname].sql shows the schema and all the data. I just can't figure out how to import it in MySQL Workbench on my local PC.
Using the MySQL Workbench Data Import tab, if I execute "Import from Dump Project Folder" where the .sql file is located, I get "There were no dump files in the selected folder."
If I select "Import from Self-Contained File" and select my ***.sql file, I get "ERROR 1142 (42000) at line 31: CREATE command denied to user 'root'#'localhost' for table 'account' Operation failed with exitcode 1"
I've attempted to give 'root'#'localhost' all privileges.
I'm guessing there's an issue with privileges. If there's another way to do this, I'd be thrilled to know it. Many thanks!
If what you have is a sql dump file then try this on the CLI:
mysql -h hostname -u user --password=password databasename < filename
Assuming of course that has the right privileges.
Non-coder here, please advise as newbie.
In that case, download heidisql : https://www.heidisql.com/
It also makes copying tables and database from server to server very easy.
Apart from that: there is most likely something wrong with your privileges. But you might have made that worse by trying to give privileges to root. The root user can already do everything. So maybe also have a look at this post : How can I restore the MySQL root user’s full privileges?
I'm struggling to use the Workbench software for a database saved on my desktop. I do normally work with SQL server online but in our case the client sent us directly the local file.
Do you know how if it is possible?
Thanks
NC
create a new database
create database database_name
import the '.sql' file provided to you into it
mysql -u username -p database_name < path/to/database_file.sql
the database will be visible then.
you can use the workbench gui instead. ensure you have created a new database first then import.
I have 5GB database that needs to be uploaded to phpmyadmin and that too on the shared server where i cannot access the shell.Is there any solution that can take lesser time to upload? Please do help me by providing the steps to upload the sql file. I have searched through internet but could not find an answer.
Do not use phpmyadmin.
Assuming you have shell, upload the file and feed it directly to mysql command.
Your shell command will look like:
cat file.sql | mysql -uuser -ppassword database
or you can do gzipped file:
zcat file.sql.gz | mysql -uuser -ppassword database
Prior doing this check:
database connection works (correct database, user and password)
database is empty :)
mysql max packet size is OK
you have enough diskspace
* UPDATE *
You said you do not have shell access.
Then you have following options -
upload the file and contact support, let they do it for you.
feed it remote, cpanel have special menu where you can get remove access, other panels have same ability too.
in this case code will be executed on your computer and look like:
cat file.sql | mysql -uroot -phipopodil -hwebsite.com
or for windows:
/path/to/mysql -uroot -phipopodil -hwebsite.com < file.sql
do some "hack" - feed it through crontab, at or via php system() command.
If you choose "hack" option, note following:
php have max_execution_time - even if you set it to zero, there could be some limit "imposed" from hosting.
usually hosts have limited mysql updates per hour.
there could be some ulimit restrictions.
if you execute feeding of 5 GB on shared server, server will slow down and administrator will check what you are doing.
This depends on your database, you tagged it with 3 different database types, mysql, sql-server, and postgresql. I know mysql and postgresql have import features, although I'd be surprised if SQL Server didn't as well. You could import the database file via the command line instead of having to use phpmyadmin.
Incidentally, the phpmyadmin tool also has an import feature, but that again depends on the format of your database. If it's a compatible sql file, you could upload it to phpmyadmin and import it there, but I'd recommend the previous method I mentioned, upload it to your host, then use whatever database tool (mysqlimport for mysql, or if it's the result of a pg_dump command, you can just run:
psql <dbname> < <yourfile>
ie
psql mydatabase < inputfile.sql
How can I import multiple files(.csv, .sql etc) into xampp mysql database ?
I am using Xampp and windows XP.
If I need to write command prompt type command, please tell in details where to find the command prompt type screen and so on.
The SQL files you can execute with MySQL command-line tool, e.g. -
shell> mysql db_name < script.sql
Load data from the CSV file into specified table you can with LOAD DATA INFILE statement.
If you do not have access to mysql client, then try dbForge Studio for MySQL. Free express edition allows to execute SQL scripts and import data from the CSV file without limitations.
This topic has been covered already, in its parts.
to import a CSV you can check this question, which will lead you to use:
LOAD DATA INFILE yourfile.csv
or if you need to update some data that is already on the database you can relate to a question I answered not long ago (and possibly other answers on stackoverflow).
You may execute this statement in the mysql prompt with mysql -u user -p -h localhost -D database (learn how to find the path to mysql.exe in your XAMMP using this question) or using some other way, such as your scripting/programming language of choice together with mysql connectors/libraries.
You may also use the mysqlimport.exe command (it'll be in the same folder as your mysql binary).
To import a sql file you can take a look at this question. You will essentially just copy the file contents into the mysql prompt, which is usually done with input redirection on the console:
C:>mysql -u user -p -h localhost -D database -o < yoursqlfile.sql
I hope that besides answering your question i might also have introduced you to the fact that with thousands(?) of questions in stackoverflow you are very likely to find the answers to your doubts by searching the questions database, possibly faster than asking your own new question.
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.