Help in clarifying syntax

Support and queries relating to all previous versions of ZoneMinder
Locked
linh
Posts: 15
Joined: Thu Apr 08, 2004 8:42 pm

Help in clarifying syntax

Post by linh »

I need help in clarifying what the documentation said.
At the site http://www.zoneminder.com/fileadmin/dow ... EADME.html, it said

For a new installation the simplest way to create your database and users is as follows,

1)
mysql mysql < zmschema.sql
Is the first mysql a command or a name of a database ?
Is the second mysql a command or a name of a database ?
would it be something like mysql my-database < zmschema.sql ?

2)
mysql mysql
Is the first mysql a command or a name of a database ?
Is the second mysql a command or a name of a database ?
would it be something like mysql my-database

3)
grant select,insert,update,delete on <your database name>.* to '<your first username>'@localhost identified by '<your first password>';
grant select,insert,update,delete on my-database to admin@localhost mypassword
Is the syntax for the command above correct ?

4)
quit

5)
mysqladmin reload

=====================
Are all of the command syntax correct ? Is there any quote needed around
the database name or the user name or the password ?

Thank you for your help.
unclerichy
Posts: 74
Joined: Wed Feb 25, 2004 5:06 pm

Post by unclerichy »

1) yes, you're correct with mysql my-database < zmschema.sql
2) same again - using your example it would be mysql my-database
3) Correct again

Easy as that :)
linh
Posts: 15
Joined: Thu Apr 08, 2004 8:42 pm

Post by linh »

Hi Unclerichy. Thank you for your help. Here is what I did in creating the sql database.
I have problem with step number 1 and that is mysql my-database < zmschema.sql

1)
[root@localhost zm-1.19.1]# mysql my-database
ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)

2)
[root@localhost zm-1.19.1]# mysql my-database < zmschema.sql
bash: zmschema.sql: No such file or directory

3) Since number 2) from above did not work, I used number 3) as shown below
[root@localhost zm-1.19.1]# mysql my-database < /usr/local/zm-1.19.1/db/zmschema.sql
ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)

Thank you for your help
unclerichy
Posts: 74
Joined: Wed Feb 25, 2004 5:06 pm

Post by unclerichy »

It looks like you may have set a password to access your mysql database. Try using mysql -p instead of just mysql, or possibly mysql -u your-username -p if you need to log in to you database with a different username 'your-username'. Either way, you should be prompted for a password.

This all assume that your mysql server and your zoneminder install are on the same machine!

Hope this helps![/b]
linh
Posts: 15
Joined: Thu Apr 08, 2004 8:42 pm

Post by linh »

Hi Unclerichy. Thank you for your help. Here is what I did in creating the sql database.
I ran the command CREATE DATABASES allusers, but it never create the database allusers

=====================================================

[root@localhost zm-1.19.1]# mysql -u root-p
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 3.23.54

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> SHOW DATABASES
-> CREATE DATABASES allusers
-> SHOW DATABASES
-> mysql allusers
-> SHOW DATABASES
->
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

Hi,

It is not 'create databases' as in your example
mysql> SHOW DATABASES
-> CREATE DATABASES allusers
-> SHOW DATABASES
-> mysql allusers
-> SHOW DATABASES
->
but 'create database'. Also you need to terminate each command with a ';' otherwise it will not be parsed.

In your original questions
1)
mysql mysql < zmschema.sql
Is the first mysql a command or a name of a database ?
Is the second mysql a command or a name of a database ?
would it be something like mysql my-database < zmschema.sql ?

2)
mysql mysql
Is the first mysql a command or a name of a database ?
Is the second mysql a command or a name of a database ?
would it be something like mysql my-database
In the first example, it can either be mysql mysql or mysql <yourdb>. It doesn't matter as the first line of zmschema.sql tells it to use the ZM database. So use either or neither, just mysql < zmschema.sql will work also. In question (2) it definitely does need to be mysql mysql as this is the system database that contains the permissions tables. In the thrid question
3)
grant select,insert,update,delete on <your database name>.* to '<your first username>'@localhost identified by '<your first password>';
grant select,insert,update,delete on my-database to admin@localhost mypassword
Is the syntax for the command above correct ?
The syntax is correct AFAIK and once you have executed this command and reloaded the permissions tables you will be able to access the database as follows mysql -h localhost -u <your first username> -p <your first password> though you may find you don't need the -h localhost part.

Phil,
unclerichy
Posts: 74
Joined: Wed Feb 25, 2004 5:06 pm

Post by unclerichy »

Almost there linh!

A few things to look out for:

1. All SQL commands must be terminated with a ';'. If you miss off the ; then mysql keeps prompting you with a ->
2. SQL commands don't need to be in upper case.
3. The syntax is CREATE DATABASE, not CREATE DATABASES (note the S)
4. Once inside the mysql command line, the command to switch databases is USE.

For reference, here's what happens when I tried it (things I type are in bold)

--------

epia# mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 46741 to server version: 4.0.13-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+----------+
| Database |
+----------+
| mysql |
| zm |
+----------+
2 rows in set (0.00 sec)

mysql> create database allusers;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+----------+
| Database |
+----------+
| allusers |
| mysql |
| zm |
+----------+
3 rows in set (0.00 sec)

mysql> use allusers;
Database changed

mysql> quit;

epia#
Last edited by unclerichy on Thu Apr 15, 2004 10:22 pm, edited 1 time in total.
unclerichy
Posts: 74
Joined: Wed Feb 25, 2004 5:06 pm

Post by unclerichy »

Phil - no fair, I was typing ;)
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

If I'd known that I'd have left you to it! You seem to be doing a pretty good job!

:lol:
linh
Posts: 15
Joined: Thu Apr 08, 2004 8:42 pm

Post by linh »

HI unclerichy. I really appreciate your help. I had been stuck with this problems for two days now. I did create a database.

database name: linh
user name: admin
password:my-pass

mysql> grant select,insert,update,delete on linh to admin@localhost identified by my-pass;
ERROR 1064: You have an error in your SQL syntax near 'my-pass' at line 1

Thank you for your help.
wmoore
Posts: 43
Joined: Mon Mar 29, 2004 2:25 am

Post by wmoore »

"mysql> grant select,insert,update,delete on linh to admin@localhost identified by my-pass;
ERROR 1064: You have an error in your SQL syntax near 'my-pass' at line 1 "

Try :

mysql> grant select,insert,update,delete on linh.* to admin@localhost identified by my-pass;

-WAM
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

The command given

grant select,insert,update,delete on <your database name>.* to '<your first username>'@localhost identified by '<your first password>';

does require you to quote your username and password, plus as pointed out above you need to add a .* after your DB name. Check the MySQL documentation for further information.

Phil,
Locked