PDA

View Full Version : Beginning with MySQL




stoid
Mar 30, 2005, 04:55 PM
I would like to be able to experiment with basic MySQL on my PowerBook, doing all work locally. I have downloaded the MySQL bit from VersionTracker, and installed it and the PrefPane no problem. I have also downloaded a front end app, CocoaMySQL but don't know how to configure the two to work together.

Also, where is a good place to get basic info on MySQL and what it's uses are.

Note: I have roughly zero experience here, and need things explained in beginner terms.

Thanks!

stoid



stoid
Apr 3, 2005, 07:03 PM
Ok, I've downloaded the MySQL Manual from their website, and know that I've got it installed properly because when I go into the terminal and type:sudo /Library/StartupItems/MySQL/MySQL start
like it says it starts and does not give me any error messages.

Next step is connecting. Do I use the mysql -h host -u user -p
?

Command Line from the Terminal?

For the time being I'm ditching CocoaMySQL, BTW.

I don't know what I should put though for host, I'm guessing I user my user short name and pass though.

Please help! Thanks


stoid

Hoef
Apr 3, 2005, 07:38 PM
If you are also in PHP you might want to try: PHP and MySQL by Ullman (http://www.amazon.com/exec/obidos/tg/detail/-/0321186486/qid=1112575039/sr=8-2/ref=sr_8_xs_ap_i2_xgl14/102-0992644-1739344?v=glance&s=books&n=507846) . Awesome book with great examples ... still using it.

stoid
Apr 3, 2005, 07:48 PM
If you are also in PHP you might want to try: PHP and MySQL by Ullman (http://www.amazon.com/exec/obidos/tg/detail/-/0321186486/qid=1112575039/sr=8-2/ref=sr_8_xs_ap_i2_xgl14/102-0992644-1739344?v=glance&s=books&n=507846) . Awesome book with great examples ... still using it.

I'd really like to be able to do it just on my local machine, but when I get ready to MySQL on the internet I'll take a look. Thanks!

Is it possible to access the install of MySQL on my laptop or does that only work on an external server.

angelneo
Apr 3, 2005, 08:22 PM
I believe the mysql installation should reside in /usr/local if I am not wrong. In that directory, you should see the mysql folder (rather long name with the version number). The bin folder inside the mysql should allow you to perform mysqld_safe, mysql so on.

stoid
Apr 3, 2005, 08:45 PM
I believe the mysql installation should reside in /usr/local if I am not wrong. In that directory, you should see the mysql folder (rather long name with the version number). The bin folder inside the mysql should allow you to perform mysqld_safe, mysql so on.

BINGO! That seems to have worked, at least now I'm getting a terminal window with the mysql> prompt like the manual shows. I'll play around a bit more, so maybe I can get this one on my own, but a friend sent me a basic sql script (filename.sql) How do I run it?

angelneo
Apr 3, 2005, 08:58 PM
BINGO! That seems to have worked, at least now I'm getting a terminal window with the mysql> prompt like the manual shows. I'll play around a bit more, so maybe I can get this one on my own, but a friend sent me a basic sql script (filename.sql) How do I run it?
There are 2 ways to use it. Both required you to use the mysql command. First way is to go into to mysql console then perform this command, "source ./filename.sql" where the filename.sql should be in the same folder. or you can directly input from the terminal command line by using "mysql database_name -u user_name -p << filename.sql" , I would prefer the first one. less prone to typo errors.

EDIT: Couldn't remember whether its "<<" or "<"

wrc fan
Apr 3, 2005, 08:59 PM
to connect from the terminal to your local host you just need to to `mysql -u root` unless you set up a password. To run the sql file just do `mysql -u root < filename.sql` (make sure before you do that that you're in the directory where that script is kept, or do the full path to the script)

EDIT: and to set a password, from inside the mysql prompt you can enter `SET PASSWORD FOR root@localhost=PASSWORD('your_new_pass');`

stoid
Apr 3, 2005, 09:16 PM
I opened up the script in BBEdit, and I see that it's just a few short and simple create table and insert into functions. I am getting the basic math/version/date functions to work, and could read/write the test database, but I'm getting permission errors when I try to create a new database.

SELECT USER(); returns:

+-----------------+
| user() |
+-----------------+
| brian@localhost |
+-----------------+
1 row in set (0.00 sec)

wrc fan
Apr 3, 2005, 09:19 PM
hmm... looks like your install wasn't set up with a root user, instead use `mysql -u brian` to replace all occourances of `mysql -u root`

Oh, and if the script doesn't create a database, you'll need to do that

mysql > CREATE DATABASE database_name;

and then run the script from the command line;

mysql -u brian database_name < filename.sql

stoid
Apr 3, 2005, 09:27 PM
I'm a bit lost here, where do I use the 'mysql -u brian'? In a standard Terminal window? When I do, I get this:

Last login: Sun Apr 3 21:10:33 on ttyp1
Welcome to Darwin!
<ComputerName>:~ brian$ mysql -u brian
-bash: mysql: command not found

angelneo
Apr 3, 2005, 09:36 PM
I'm a bit lost here, where do I use the 'mysql -u brian'? In a standard Terminal window? When I do, I get this:

Last login: Sun Apr 3 21:10:33 on ttyp1
Welcome to Darwin!
<ComputerName>:~ brian$ mysql -u brian
-bash: mysql: command not found

You have to locate the mysql command which should be in the bin folder of mysql installation and execute from there.

wrc fan
Apr 3, 2005, 09:41 PM
Assuming mysql is installed in the default location do this to add it to your path:

echo 'export PATH=$PATH:/usr/local/mysql/bin' >> ~/.profile

then do:

source ~/.profile

and then mysql will be in your path and you can run the command from anywhere.

stoid
Apr 3, 2005, 09:48 PM
Maybe this is what you were trying to tell me to do, but I typed:

sudo /usr/local/mysql/bin/mysql -u root
into a bash terminal window, and it logged me into the mysql as user 'root@localhost' and is letting me create a database. Unless there is a simpler way to login in the future... but this works for now. Thanks again for all your help!!

superbovine
Apr 4, 2005, 04:36 AM
Maybe this is what you were trying to tell me to do, but I typed:

sudo /usr/local/mysql/bin/mysql -u root
into a bash terminal window, and it logged me into the mysql as user 'root@localhost' and is letting me create a database. Unless there is a simpler way to login in the future... but this works for now. Thanks again for all your help!!

http://www.sitepoint.com/

down at the bottom right is a like for a book on php and mysql. it has the first 3 chapters in pdf. it will answer all the question you are having. it even has Mac specific examples.

This only applies if you are using bash. You can tell by typing echo $SHELL. if you see: '/bin/bash/' you are using bash.

as to your question about logining in. you can simply matters by making a script by editing your the ~/.bashrc file. Another poster tried to get you do it but his ~/.profile was wrong. don't use textedit causes problems. the easiest way is from the command like and type 'pico .bashrc'. although, you can edit it with emacs or vi if you would like.

anyways add this line to your ~/.bashrc

export PATH=/usr/local/mysql/bin:$PATH

ctrl-x to save.
exit out of terminal and open a new session.

the line will make every command in /usr/local/mysql/bin accessable to you without typing the long command line.

also, i use a script to login to mysql. use 'pico lm' and enter (ctrl-x to save)

mysql -h localhost -u loginName -p

then from terminal do chmod 766 lm. now you do './lm' and simply login.

wrc fan
Apr 4, 2005, 12:48 PM
Another poster tried to get you do it but his ~/.profile was wrong.

No it's not wrong. Try adding something to your .profile file, and you'll see it works just fine. Just cause one thing is your custom doesn't mean doing it a different way is wrong.


also, i use a script to login to mysql. use 'pico lm' and enter (ctrl-x to save)

mysql -h localhost -u loginName -p


I could just as easily say that's wrong because there's no reason to specify host when connecting to localhost, but since it works fine, you can't really say it's wrong.


Now back to stoid, I think your problem is that you didn't start up mysql with sudo. So next time you want to turn it on use `sudo mysql_safe`. The reason I say that is because you shouldn't have to run the mysql command as an administrator. The only other thing might be that the /usr/local/mysql/data folder might not have the correct permissions. So if running the `sudo mysql_safe` doesn't fix it, then you should run `chown -R mysql /usr/local/mysql/data`

MacNemesis
Apr 26, 2005, 10:32 PM
I would like to be able to experiment with basic MySQL on my PowerBook, doing all work locally. I have downloaded the MySQL bit from VersionTracker, and installed it and the PrefPane no problem. I have also downloaded a front end app, CocoaMySQL but don't know how to configure the two to work together.

Also, where is a good place to get basic info on MySQL and what it's uses are.

Note: I have roughly zero experience here, and need things explained in beginner terms.

Thanks!

stoid

If you want to use CocoaMySQL just use "localhost" as the host, then use a valid MySQL username and password. Just remember that these are NOT the same as your Mac's username(s)/password(s).