Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

stoid

macrumors 601
Original poster
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

macrumors 601
Original poster
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:
Code:
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
Code:
mysql -h [I]host[/I] -u [I]user[/I] -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
 

stoid

macrumors 601
Original poster
Hoef said:
If you are also in PHP you might want to try: PHP and MySQL by Ullman . 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

macrumors 68000
Jun 13, 2004
1,541
0
afk
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

macrumors 601
Original poster
angelneo said:
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

macrumors 68000
Jun 13, 2004
1,541
0
afk
stoid said:
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

macrumors 65816
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

macrumors 601
Original poster
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:

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

wrc fan

macrumors 65816
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

macrumors 601
Original poster
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:

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

angelneo

macrumors 68000
Jun 13, 2004
1,541
0
afk
stoid said:
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:

Code:
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

macrumors 65816
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

macrumors 601
Original poster
Maybe this is what you were trying to tell me to do, but I typed:

Code:
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

macrumors 68030
Nov 7, 2003
2,872
0
stoid said:
Maybe this is what you were trying to tell me to do, but I typed:

Code:
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

Code:
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)

Code:
mysql -h localhost -u loginName -p

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

wrc fan

macrumors 65816
superbovine said:
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.

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

Code:
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

macrumors member
Apr 12, 2005
46
0
Cincinnati, OH
stoid said:
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).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.