Creating SQL database

Place to discuss Fedora and/or Red Hat

Creating SQL database

Postby agent007 » Fri Jan 02, 2004 1:14 pm

hi all,

I've installed apache+mySQL.....how do I create a new database from the command line? I also need to add a user and password....can this be done from the command line?

thanks.
agent007
administrator
administrator
 
Posts: 254
Joined: Wed Feb 12, 2003 11:26 pm

Postby Tux » Fri Jan 02, 2004 3:15 pm

==> Create User agent007:

# mysql -u root
> use mysql;
> insert into user (host, user, password) VALUES ('localhost', 'agent007', PASSWORD('yourpass'));
> flush privileges;
> exit;

==> Create database agentdb with modification rights given to user agent007:

# mysql -u root
> use mysql;
> create database agentdb
> grant all privileges on agentdb.* to 'agent007';
> flush privileges;
> exit;
Tux
guru
guru
 
Posts: 689
Joined: Wed Jan 08, 2003 10:40 am

Postby Void Main » Sat Jan 03, 2004 7:38 pm

You might also look in to some of the other MySQL commands for alternate ways of doing that. Commands like mysqladmin and mysqlaccess.
User avatar
Void Main
Site Admin
Site Admin
 
Posts: 5705
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA

Postby agent007 » Sun Jan 04, 2004 12:23 pm

hi guys!

Thanks for the help......After issuing the command
mysql -u root

The following error comes up:
ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)


What does it mean?

thanks..
agent007
administrator
administrator
 
Posts: 254
Joined: Wed Feb 12, 2003 11:26 pm

Postby Void Main » Sun Jan 04, 2004 3:59 pm

Did you set a password for your root MySQL user? If so you need to add the "-p" parameter so it will prompt you for your password.
User avatar
Void Main
Site Admin
Site Admin
 
Posts: 5705
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA

Postby agent007 » Mon Jan 05, 2004 11:55 am

oh great...I dont think so...I was playing aound earlier before and may have put a password which i have no idea of now...Is there a way to reset it? i'll try uninstalling and reinstall mysql to c if it gets rid of it.....

thanks..
agent007
administrator
administrator
 
Posts: 254
Joined: Wed Feb 12, 2003 11:26 pm

Postby agent007 » Tue Jan 06, 2004 11:08 am

Right, reinstalling did not work..SO now what? Is there a way to reset the password?
agent007
administrator
administrator
 
Posts: 254
Joined: Wed Feb 12, 2003 11:26 pm

Postby Tux » Tue Jan 06, 2004 11:18 am

Try using just 'mysql', if that works ill tell you how to set a root password.
Tux
guru
guru
 
Posts: 689
Joined: Wed Jan 08, 2003 10:40 am

Postby Void Main » Tue Jan 06, 2004 11:25 am

No, "reinstalling" won't work unless you actually delete the MySQL database between the "remove" and the "install". The MySQL system database is created at install time. When you remove MySQL it only removes the program files and not the database that was created, which is normally a good thing. In MySQL packaged for RH/FC the MySQL databases are physically stored under the /var/lib/mysql directory.

Having said that, yes, there are other ways to recover a lost MySQL root password:

http://www.mysql.com/doc/en/Resetting_permissions.html

Please also read the reader comments at the bottom of the above page before doing anything.
User avatar
Void Main
Site Admin
Site Admin
 
Posts: 5705
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA

Postby Tux » Tue Jan 06, 2004 11:28 am

Void Main wrote:No, "reinstalling" won't work unless you actually delete the MySQL database between the "remove" and the "install". The MySQL system database is created at install time. When you remove MySQL it only removes the program files and not the database that was created, which is normally a good thing. In MySQL packaged for RH/FC the MySQL databases are physically stored under the /var/lib/mysql directory.

Having said that, yes, there are other ways to recover a lost MySQL root password:

http://www.mysql.com/doc/en/Resetting_permissions.html


Indeed, although as far as I understand he doesn't currently have a root password?
Tux
guru
guru
 
Posts: 689
Joined: Wed Jan 08, 2003 10:40 am


Return to Fedora/Red Hat

Who is online

Users browsing this forum: No registered users and 0 guests

cron