I am newbie to MySQL.I create a database in MySQL in command shell by "create database DBNAME". But I can not use my own created database.So friends help me how to log into my database named "DBNAME" because I want to create some tables in that.

Thank You

Ok

The next time you open mysql, after logging in to your server, execute use "DBNAME"

remember in mysql, every time you open a connection you have to specify which database to use, and if that was not your problem, have you tried using the root account? because automatically you should have privileges to that DB with the user you created it with, and root will always have superior access to them all just like root account works in Unix and Linux

Ok, Let me say MSQL is a very interesting database to use, but also frustrating when your database is not interacting with you. let me breakk it down for you step by step.

1. depending on the set up u're using ok
2. if u're using XAMPP, thats cool because it contains PHP,MYSQL and APACHE server for your web application.
3. just go through the installations, after that
4. they will display a SMALL CONTROL panel on the RIGHT BOTTOM of your computer screen.
5. Check to see if all the 3 things (

Apache,Mysql and Filezilla

) are running.
6.if not Success. i.e they are not running,
7. then congrates
8. it's now time for u to go to your XAMPP and create tables
9. Open your browser, and then type in localhost
10. this should open the XAMPP page,
11. then you click on PHPmyadmin.
12. on the screen you will see an input create new database.
13. type the name of the database of your choice i.e "store" and the click the create button.
14. you should see some message, database created .
15. look at the left of your computer, you will find the database you've created there.
16 click on the database name, so that it will take you to another page were you will find no tables in database .
17. then type the name of your table in the create table in database nameofdatabase, field number, maybe "1" , and then click the GO button.
18. then on the next page,choose the name to assign your table and then select the length. that's all, then click GO.
19. Msg will be shown table created.
20. thats how to create tables in XAMPP..

using the Mysql commandline, here's what to do
1. open your command prompt. " only if you have installed the Mysql 5 on your computer.
2. in your command line, type in mysq -u root, because you will be using the root loggin.
3. when it opens , you will see something like this mysql >, meaning you have logged in sucessfully.
4. type in SHOW DATABASE;.pls mind you that the Capslock is very important in this command line.
5. then it's time for you to create your database.
6. type in the commandline

CREATE DATABASE yourdatabasename;

e.g CREATE DATABASE store;.
7. type in

USE store;

, you should see this Database Changed
8. then create a table with elements in it now.
9. type

CREATE TABLE yourtablename

, and the declare the elements like this
10.

CREATE TABLE students (
             id_no INT NOT NULL AUTO_INCREMENT,
             name VARCHAR(150),
             age INT(3),
             school VARCHAR(150),
             PRIMARY KEY(id_no));

.
11. this line of code will create a table named students, with attributes like id_no,name,age,school.
12. that's how to create a table in Mysql commandline.

.

How to use your created database is like this

You will need to create a connection first with your database.
here's how to connect with your database.

mysql_connect(localhost,root) or die("could not connect to database" .mysql_error());
mysql_select_db("yourdatabasename") or die(mysql_error());

.

PLEASE MAKE SURE YOU INPUT YOU DATABASE NAME , AND NOT YOUR TABLE NAME OK because peolpe make that mistake so much.
For example if my DATABASE NAME IS STORE, what you should do is this

mysql_connect(localhost,root) or die(mysql_error());
mysql_select_db("store") or die(mysql_error());

.
THAT'S ALL I HAVE, PLS IF ANY CONFUSSION, JUST NOTIFY ME OK. THANKS AND CHEERS WITH YOUR DATABASE CREATION..

You can edit or delete the said database by using stored procedure statement.

Ok guys, lets not get ahead of the OP, i don't think stored procedures would be relevant in this matter.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.