View Full Version : mySQL problem
Mortimer Jazz
10-30-2003, 01:30 PM
Hello. Just swapped over from using a preconfigured package (Firepages) to installing everything separately, and I'm having a couple of small problems with mySQL.
When I check the environment tab in winmysqladmin, in the ODBC pane it says Driver 3.51 not found. Is this correct? (I've got the latest versions of M.A.P.)
I don't seem to be able to set a username and password for mySQL In the my.ini file it was set to be "test" and "test" but the following code didn't work:
<?php
$link = mysql_connect("localhost","test","test");
if(!$link){
mysql_error();
print "can't connect to server\n<br>";
}else{
print "Connection successful";
}
print "--------------------------\n<br>";
$Version = mysql_get_server_info();
$HostInfo = mysql_get_host_info();
print "My current MySQL version is: $Version / $HostInfo";
?>
(it told me I couldn't connect, but did tell me version and host info). I now have to set everything to an empty string to get a successful connection (I tried restarting the server etc). I'd like to have a password and username if possible.
Finally, with the Firepages package I could start up all the services from one link. Here, I have to start apache and mySQL separately. Are there any decent tutes on how to do this?
Cheers,
M
butterbur
10-30-2003, 03:21 PM
You don't need an ODBC driver for connecting with PHP.
I think the problem with accepting your connection variables is the quotation marks, try instead:
$link = mysql_connect(localhost,test,test);
Mysqladmin will normally start up automatically however if this is not the case then if you're using windows then simply add the two programs to your startup group.
freddycodes
10-30-2003, 03:43 PM
No no no, strings are strings and should be treated as such, enclosed in double quotes.
Mortimer,
Is the mysql server running when you run that script? Is there actually a user with name test and password test?
Can you log into mysql from the command line?
If so, I would suggest adding a user that way. Log in as root
mysql>grant all on *.* to test@localhost identified by 'test';
mysql>flush privileges
Now you should be able to connect from PHP.
Mortimer Jazz
10-30-2003, 04:06 PM
Thanks both. Okay, I have little understanding when it comes to command line stuff so excuse the longish explanation (spot the guy who never used a pc before Win2000 - lol)
----------------------------------------------------------------------------
Yes, the mySQL server is running when I run the script (I have a green light) on winmysqladmin's task-bar icon
my.ini contains this:
user="test"
password="test"
Not sure whether that means there is a user defined or not.
----------------------------------------------------------------------------
When I run the code in my above post I get:
can't connect to server
My current MySQL version is: 3.23.58-nt / localhost via TCP/IP
----------------------------------------------------------------------------
When I open my command promp and cd to mysql/bin I try this:
C:\mysql\bin>mysql.exe -h localhost -u test -ptest localhost
I have no idea if this is right, but it's the same method as I use to log on to my remote server, replaced with my local details
It gives me the message "Can't connect to MySql server on 'localhost' (10061)"
----------------------------------------------------------------------------
I didn't want to do the grant/flush thing just yet until I know if I'm doing something very obviously wrong - I guess I am ;]
freddycodes
10-30-2003, 04:12 PM
Yeah the server is definitely not running. Or else you would be able to connect. Also you don't really need the my.ini file at this point.
First thing to do is setup MySQL as a service on windows 2000. Then you can start and stop the server from the Service Panel in Windows 2000. Accessible through Control Panel > Administrative Tools > Services.
To do this start here
http://www.mysql.com/documentation/mysql/bychapter/manual_Installing.html#Windows
Look at how to instal lthe mysql server as a service. Also by default mysql root user has no password, this is fine for local testing. So you should be able to login from the commanbd prompt as
C:\>mysql -u root
Mortimer Jazz
10-30-2003, 04:33 PM
Gah, instructions wern't made for us post-commandline people.
Okay excuse the dumb question (I'm on XP now, so I'm looking at the link you posted for stopping the server using the command line).
It tells me to enter: shell> C:\mysql\bin\mysqladmin -u root shutdown
That's fine, except how on earth do I get to shell>?
I know this may sound stupid, as I think it just means from the command line right? But I'm not sure.
I think it would be a good idea for me to learn some command line stuff/DOS because I feel so helpless when I read these manuals, and really they should be making sense.
I tried C:\mysql\bin>mysqladmin.exe -u root shutdown but that doesn't work (I get told to check that mysqld is running on localhost on port 3306 by telneting. I do this and it isn't).
-------------------------------------------------------------------------------
I've been using root and "", and everything works well, but I'd still like to knwo what's going wrong.
Out of interest, would it still not be a security issue then? I'm behind a firewall anyway, but if I wasn't wouldn't it be possible for someone to gain access to my local machine whilst I'm online if I have mySQL running with default settings?
Cheers
Mortimer Jazz
10-30-2003, 04:47 PM
also, my phpscript seems to be showing mysql to be working, but if I type in C:\> C:\mysql\bin\mysql test (as per the link you posted) I'm told it isn't.
Does anyone actually understand that manual? Lol
freddycodes
10-30-2003, 04:50 PM
I completely understand it, but I also remember installing MySQL for the first time, and it was not fun. Now it takes me about 2 minutes to install a fresh copy.
You can't shutdown a server that isn't running. There are two ways to run mysql one has a standalone server and one as a windows service, I would suggest the latter ALWAYS.
You see the part about mysqld.exe --install which installs mysql as a service.
Once that is done you can start and stop it by using
net start mysql
and
net stop mysql
from the commandline.
Once you have that started you should be able to do
C:\mysql\bin>mysql -u root
And get access to the test database from the mysdl console in the commandline.
Mortimer Jazz
10-31-2003, 04:58 AM
Thanks Freddy.
--------------------------------------------------------------------------------
NET START MYSQL tells me that mySQL has already been started
I can also see from the admin>services panel that mySQL is already running as a web service. It's set to start automatically.
[edit - I just realised that I couldn't connect because of my ZoneAlarm settings (mysql.exe, mysqld.exe etc were set for trusted zones only). They now have full access for both trusted & internet zones - isn't this a security problem when I'm online?
freddycodes
10-31-2003, 11:58 AM
I mean I guess technically yes. But but do you have a router/firewall between your computer and the web?
Also this is not meant to be sarcastic at all, well maybe a little. But what you aren't storing credit card numbers and whatnot in this database right? So what the fuss for ;)
Make sure root has a password and remove all entires from the user table of the mysql database that allow remote access to the mysql server ie. any entry with a % in the host column.
Mortimer Jazz
10-31-2003, 02:13 PM
yep, zonealarm is my firewall, but I've had to grant apache and mysql access anyway, so...
You .... sarcastic?
I'm so green about these things that I would have no idea if allowing access to apache/mySQL could possibly also give hackers a gateway to the rest of my machine too - so I thought it best to ask. Goodness knows what state i'd end up in if they got in and maliciously deleted all my porn :eek: ;)
Thanks Freddy.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.