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.
Related
I have a MySQL database hosted on Digital Ocean Managed Database service. I lost my previous dev machine and did not push the Schema to git along with application files. I am desperate to get back the SQL Schema in my local machine for further Development but have so far been usuccessfull. I have tried so many commands from different suggestions but they all failed.
I connect to the DB via the MySQL Shell using the command:
mysql -u username -password-h example-test-do-user-7878789-0.b.db.ondigitalocean.com -P 25060 -D example_db
All queries are executed successfully via this shell method. When trying to Dump the Schema to my machine, I use the following command:
mysql -u username -p -h mysql-test-do-user-4915853-0.db.ondigitalocean.com -P 25060 your_database_name \> database_file_name.sql
But I get the error as follows: mysqldump: unknown variable 'set-gtid-purged=OFF'
if I remove that part and try again, I get the error:
mysqldump: Got error: 2003: "Can't connect to MySQL server on 'localhost' (10061 "Unknown error")" when trying to connect
which doesnt make sense to me. So, without further ranting; How to I achieve my intended result.
NOTE: I did try Mysql workbench, but it won't connect all together
I can appreciate trying to achieve what you want via mysql shell. I stumbled across the same problem and for quite some tie did not find the help i needed, then I tried doing it using mysql workbench. Try it and you will find that its easier than usin the command-line approach. MySQL Workbench has a good GUI based database miguration capability. You can migrate you Do Managed DB directly into you local mysql server or export a schema dump. If you decide to go wit this approach, just make sure you add your machine's IP as a trusted source, else you will not be able to connect.
I am creating a Software configuration for MySQL 5.6.22 and I'll need to create the root administration user root:rootroot.
Next step, I'll need to install as service/daemon with auto-start option and finally this installation needs:
MySQL Workbench 6.2.4
MySQL Connector/J 5.1.34
To configure the Data Base on RNL Lab of the project the programmer shell do:
The mysql -uroot -p try to connect to the server and it won't have access to it.
The programmer shell always use mysql-local-client, this might work as an alias to the root, while the pass maintains the same as "root".
For running the project it must be started by the MySQL Server on the working Computer:
mysql-local-start
At the end it might encounter the running server port (should be the 10000 or 10001).
After that it must have a connection to the server, using other command line, to creating the user, give the right privilege and finally for creating the Data Base with:
mysql-local-client
It's necessary to use this command, that works as an alias for the last server created.
Please run the next commands on MySQL Shell from the mysql-local-client:
CREATE USER 'bubble'#'localhost' IDENTIFIED BY 'bubbl3';
CREATE USER 'bubble'#'%' IDENTIFIED BY 'bubbl3';
GRANT ALL PRIVILEGES ON bubbledb.* TO 'bubble'#'localhost';
GRANT ALL PRIVILEGES ON bubbledb.* TO 'bubble'#'%';
CREATE DATABASE bubbledb;
At last it needed to change the properties for the Fenix Framework so that the next code runs (where 10000 is the running server port):
dbAlias=//localhost:10000/bubbledb?useUnicode=true&characterEncoding=UTF-8&clobCharacterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
dbUsername=bubble
dbPassword=bubbl3"
Alright, so I've got a fairly fresh Ubuntu (server) installation. Just finished installing the LAMP server and when I go to create a database I'm getting the generic syntax error (1064 / 42000).
My query:
CREATE DATABASE phpbb;
Pretty simple and pretty standard, so I'm not sure what the issue is. Any ideas?
It looks from your error like you're trying to execute SQL on the command line, something like:
mysql -u mike -p CREATE DATABASE phpbb';
MySQL isn't going to like that, it separates the initiation of the tool from the SQL commands.
What I'd normally do for CREATE DATABASE, as it's a one off, I'd do it manually.
So start the tool with
mysql -u mike -p
This should prompt you for your password, and connect to the local database, giving you a shell prompt:
mysql>
You then issue your
CREATE DATABASE phpbb;
If you want to run scripts from the command line, put them in a file and redirect the input to mysql. Usually you'd redirect the output too - something like this:
mysql -u mike -p < mysqlscript.sql > outputofscript.log
I don't know much about MySQL at all. But I am trying to reverse engineer a MySQL database using Visio. I know what steps I should take to do this, but I can't get my database to show in the 'Databases' section (as below):
How do I create the MySQL database using the .SQL file and get it to show up in this list? I have tried this code:
mysql -u username -p password database_name < filename.sql
using my own credentials of course. But that doesn't seem to work. In what folder should the .SQL file be placed if this statement is to work?
1) Create a file "filename.sql"
2) Create a database in your DB in which you want to import this file.
3) From command-prompt/terminal, move to the directory where you have created a "filename.sql".
4) Run the command: mysql -u username -p password database_name < filename.sql. (You can also give the proper path of your file and run this command from anywhere). It might be the case that you don't have a password set for MySQL. If so, mysql -u username database_name < filename.sql will also work.
In your case if you have created a database with name ojs and also created a file with name ojs.sql in C: drive then run the following command:
Edit: Put the path inside quotes.
mysql -u username -p password ojs < "C:\ojs.sql"
There is another way of importing tables in mysql. You can do it this way as well:
1) Connect your database
2) Type command "use ojs;"
3) Type command "source C:/ojs.sql"
Most MySQL SQL files that create databases create the database 'on-the-fly', so you typically needn't do anything except:
log-in
mysql -u [username] -p[password]
(Note: make sure you do NOT include a space (' ') character between the -p and the [password].
MySQL will think that [password] is the name of the database you want to connect to.
The 'general' log-in (above) does not assume you want to connect to any particular schema.)
source the file (do not use quotes around filename)
mysql> source [database_creation_file].sql
you can simply do it using mysql workbench
1> create a new query tab
2> CREATE DATABASE database_name;
3> USE database_name;
4> open the filename.sql file and execute it ctrl + shift + enter
5> all the tables in the filename.sql are created
To create a MySQL database using a SQL file, you can follow these steps:
Log in to your MySQL server using the mysql command-line tool and the appropriate credentials.
Use the CREATE DATABASE command to create a new database with the desired name:
CREATE DATABASE database_name;
Use the USE command to switch to the newly created database:
USE database_name;
Use the SOURCE command to import the SQL file into the database:
SOURCE path/to/sql/file;
The database will now be created and populated with the data from the SQL file. You can verify this by running some SQL queries against the database.
It's important to note that this process assumes that the SQL file contains valid SQL statements compatible with the version of MySQL you are using. If the SQL file contains any errors or unsupported statements, they will be displayed in the mysql command-line tool, and the import process will be interrupted.
I am trying to learn PHP and MySQL and while I reached a chapter on MySQL I was asked to create a database using this command:
CREATE DATABASE publications;
After I typed it in the mysql console I got this error:
ERROR 1044(42000):Access denied for user ''#localhost' to database 'root'
I am already logged in to my administrator account so I think the privileges should't be a problem.I have installed with the XAMPP package.
How can this be solved?
It could be possible that you upgraded your version of EasyPHP or you did something to disable the root password. If that is the case, you should try reestablishing a password for root. Had the same problem and that's how I solved it.
Go to http://localhost/xampp/ and set the appropriate passwords (in Security tab). If you use mysql client program, make sure you call it with appropriate credentials: mysql -u <username> -p <password>. Username will mostly be root until you create some new accounts.
Then I suggest you use phpMyAdmin for experimenting with MySQL (it should be at http://localhost/phpmyadmin/ )
This is getting a little confused - let me try to answer this.
Mysqladmin is a command line client for administering your mysql database system - you normally don't need to run it once you have mysql working. The shell command line interface to the mysql server is mysql. (If you don't know how to run a shell command line, that's another problem. Also, if you're on Windows, say so, since that has its own challenges.) The arguments are:
mysql -u username -ppassword databasename
if you are running this command on the same server as mysql. Note the lack of space after the -p - that is important.
So, type the above line to invoke the command line interface to mysql. Then you can type your mysql commands. Things like show tables, desc tablename, etc., will work. That is they will work unless you have an authentication problem. But you will know you have an authentication problem because when you tried to run mysql as above, it will fail with some error, like "Access denied for user 'abc'#'localhost' (using password: YES)". This is a nice descriptive error message that points you exactly where the problem is.
Does that help?
You can go back to using xampp or anything else once you've made sure that you know the right parameters by checking with the command line. (Always check with the command line when strangeness happens - it's so much easier than trying to debug through other interfaces.)