Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MySql Newb - General Question about Tutorial on Web

Posted on 2010-08-16
9
Medium Priority
?
510 Views
Last Modified: 2013-11-12
Hi, I am trying to follow some instructions on getting Asterisk into a MySql DB.  I have absolutely no idea what the following is telling me to do.  Should I be entering these as commands into a mysql console of some sort?

Here is the portion that has me hung up:

Configure MySQL (optional)
The information below shows table definitions for all of the tables Asterisk can use with MySQL or ODBC.

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

##
##Database: `asterisk`
##
CREATE DATABASE `asterisk` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `asterisk`;

##########################################################

##
##Table structure for table `cdr`
##

CREATE TABLE IF NOT EXISTS `cdr` (
 `recid` mediumint(8) unsigned NOT NULL auto_increment COMMENT 'Record ID',
 `calldate` datetime NOT NULL default '0000-00-00 00:00:00',
 `clid` varchar(80) NOT NULL default '',
 `src` varchar(80) NOT NULL default '',
 `dst` varchar(80) NOT NULL default '',
 `dcontext` varchar(80) NOT NULL default '',
 `channel` varchar(80) NOT NULL default '',
 `dstchannel` varchar(80) NOT NULL default '',
 `lastapp` varchar(80) NOT NULL default '',
 `lastdata` varchar(80) NOT NULL default '',
 `duration` int(11) NOT NULL default '0',
 `billsec` int(11) NOT NULL default '0',
 `disposition` varchar(45) NOT NULL default '',
 `amaflags` int(11) NOT NULL default '0',
 `accountcode` varchar(20) NOT NULL default '',
 `uniqueid` varchar(32) NOT NULL default '',
 `userfield` varchar(255) NOT NULL default '',
 PRIMARY KEY  (`recid`),
 KEY `calldate` (`calldate`),
 KEY `dst` (`dst`),
 KEY `accountcode` (`accountcode`),
 KEY `src` (`src`),
 KEY `disposition` (`disposition`),
 KEY `uniqueid` (`uniqueid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

##########################################################

##
##Table structure for table `queue_members`
##

CREATE TABLE IF NOT EXISTS `queue_members` (
  `queue_name` varchar(128) NOT NULL default '',
  `interface` varchar(128) NOT NULL default '',
  `penalty` int(11) default NULL,
  PRIMARY KEY  (`queue_name`,`interface`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

##########################################################

##
##Table structure for table `queues`
##

CREATE TABLE IF NOT EXISTS `queues` (
  `name` varchar(128) NOT NULL,
  `musiconhold` varchar(128) default 'default',
  `announce` varchar(128) default NULL,
  `context` varchar(128) default NULL,
  `timeout` int(11) default '60',
  `monitor_join` tinyint(1) default NULL,
  `monitor_format` varchar(128) default NULL,
  `queue_youarenext` varchar(128) default NULL,
  `queue_thereare` varchar(128) default NULL,
  `queue_callswaiting` varchar(128) default NULL,
  `queue_holdtime` varchar(128) default NULL,
  `queue_minutes` varchar(128) default NULL,
  `queue_seconds` varchar(128) default NULL,
  `queue_lessthan` varchar(128) default NULL,
  `queue_thankyou` varchar(128) default NULL,
  `queue_reporthold` varchar(128) default NULL,
  `announce_frequency` int(11) default NULL,
  `announce_round_seconds` int(11) default NULL,
  `announce_holdtime` varchar(128) default NULL,
  `periodic_announce` varchar(128) default NULL,
  `periodic_announce_frequency` int(11) default NULL,

  `retry` int(11) default '5',
  `ringinuse` varchar(5) NOT NULL default 'no',
  `autofill` varchar(5) NOT NULL default 'yes',
  `autopause` varchar(5) NOT NULL default 'no',
  `setinterfacevar` varchar(5) NOT NULL default 'yes',
  `wrapuptime` int(11) default '30',
  `maxlen` int(11) default NULL,
  `servicelevel` int(11) default NULL,
  `strategy` varchar(128) default 'ringall',
  `joinempty` varchar(128) default 'no',
  `leavewhenempty` varchar(128) default 'yes',
  `eventmemberstatus` tinyint(1) default NULL,
  `eventwhencalled` tinyint(1) default NULL,
  `reportholdtime` tinyint(1) default NULL,
  `memberdelay` int(11) default NULL,
  `weight` int(11) default NULL,
  `timeoutrestart` tinyint(1) default NULL,
  PRIMARY KEY  (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

##########################################################

##
##Table structure for table `sip`
##

CREATE TABLE IF NOT EXISTS `sip` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(80) NOT NULL,
  `host` varchar(31) NOT NULL default 'dynamic',
  `nat` varchar(5) NOT NULL default 'no',
  `type` enum('user','peer','friend') NOT NULL default 'friend',
  `accountcode` varchar(20) default 'ACCOUNT',
  `amaflags` varchar(13) default NULL,
  `callgroup` varchar(10) default NULL,
  `callerid` varchar(80) default NULL,
  `call-limit` varchar(6) NOT NULL default '10',
  `cancallforward` char(3) default 'yes',
  `canreinvite` char(3) default 'no',
  `context` varchar(80) default 'from-sip',
  `defaultip` varchar(15) default NULL,
  `dtmfmode` varchar(7) default 'rfc2833',
  `fromuser` varchar(80) default NULL,
  `fromdomain` varchar(80) default NULL,
  `insecure` varchar(4) default NULL,
  `language` char(2) default 'en',
  `mailbox` varchar(50) default NULL,
  `md5secret` varchar(80) default NULL,
  `deny` varchar(95) default '0.0.0.0/0.0.0.0',
  `permit` varchar(95) default '0.0.0.0/0.0.0.0',
  `mask` varchar(95) default NULL,
  `musiconhold` varchar(100) default 'default',
  `pickupgroup` varchar(10) default NULL,
  `qualify` char(3) default 'yes',
  `regexten` varchar(80) default NULL,
  `restrictcid` char(3) default NULL,
  `rtptimeout` char(3) default NULL,
  `rtpholdtimeout` char(3) default NULL,
  `secret` varchar(80) default 'SECRET',
  `setvar` varchar(100) default NULL,
  `disallow` varchar(100) default 'all',
  `allow` varchar(100) default 'alaw',
  `fullcontact` varchar(80) NOT NULL default '',
  `ipaddr` varchar(15) NOT NULL default '',
  `port` smallint(5) unsigned NOT NULL default '0',
  `regserver` varchar(100) default NULL,
  `regseconds` int(11) NOT NULL default '0',
  `username` varchar(80) NOT NULL,
  `defaultuser` varchar(80) NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `name` (`name`),
  KEY `name_2` (`name`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC AUTO_INCREMENT=301 ;

##########################################################

##
##Table structure for table `voicemail_messages`
##

CREATE TABLE IF NOT EXISTS `voicemail_messages` (
  `id` int(11) NOT NULL auto_increment,
  `msgnum` int(11) NOT NULL default '0',
  `dir` varchar(80) default '',
  `context` varchar(80) default '',
  `macrocontext` varchar(80) default '',
  `callerid` varchar(40) default '',
  `origtime` varchar(40) default '',
  `duration` varchar(20) default '',
  `mailboxuser` varchar(80) default '',
  `mailboxcontext` varchar(80) default '',
  `recording` longblob,
  PRIMARY KEY  (`id`),
  KEY `dir` (`dir`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1088 ;

##########################################################

##
##Table structure for table `voicemail_users`
##

CREATE TABLE IF NOT EXISTS `voicemail_users` (
  `uniqueid` int(11) NOT NULL auto_increment,
  `customer_id` varchar(11) NOT NULL default '0',

  `context` varchar(50) NOT NULL default 'default',
  `mailbox` varchar(11) NOT NULL default '0',
  `password` varchar(5) NOT NULL default '6666',
  `fullname` varchar(150) NOT NULL,
  `email` varchar(50) NOT NULL,
  `pager` varchar(50) NOT NULL,
  `tz` varchar(10) NOT NULL default 'en',
  `attach` varchar(4) NOT NULL default 'yes',
  `saycid` varchar(4) NOT NULL default 'yes',
  `dialout` varchar(10) NOT NULL,
  `callback` varchar(10) NOT NULL,
  `review` varchar(4) NOT NULL default 'no',
  `operator` varchar(4) NOT NULL default 'no',
  `envelope` varchar(4) NOT NULL default 'no',
  `sayduration` varchar(4) NOT NULL default 'no',

  `saydurationm` tinyint(4) NOT NULL default '1',
  `sendvoicemail` varchar(4) NOT NULL default 'no',
  `delete` varchar(4) NOT NULL default 'no',
  `nextaftercmd` varchar(4) NOT NULL default 'yes',
  `forcename` varchar(4) NOT NULL default 'no',
  `forcegreetings` varchar(4) NOT NULL default 'no',
  `hidefromdir` varchar(4) NOT NULL default 'yes',
  `stamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`uniqueid`),
  KEY `mailbox_context` (`mailbox`,`context`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=101 ;

## ########################################################

##
##Create realtime user with approximately the right privs.
##

CREATE USER 'astrealtime'@'localhost' IDENTIFIED BY 'MYPASS';
GRANT FILE ON * . * TO 'astrealtime'@'localhost' IDENTIFIED BY 'MYPASS' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
GRANT INSERT ON `asterisk`.`cdr` TO 'astrealtime'@'localhost';
GRANT SELECT , INSERT , UPDATE , DELETE ON `asterisk`.`queue_members` TO 'astrealtime'@'localhost';
GRANT SELECT , UPDATE ON `asterisk`.`queues` TO 'astrealtime'@'localhost';
GRANT SELECT , UPDATE ON `asterisk`.`sip` TO 'astrealtime'@'localhost';
GRANT SELECT , UPDATE ON `asterisk`.`voicemail_users` TO 'astrealtime'@'localhost';
GRANT SELECT , UPDATE , INSERT , DELETE ON `asterisk`.`voicemail_messages` TO 'astrealtime'@'localhost';
0
Comment
Question by:jkockler
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
9 Comments
 
LVL 32

Expert Comment

by:DrDamnit
ID: 33448690
It's asking you to create the databases. Are you using Windows or Linux?
0
 
LVL 4

Author Comment

by:jkockler
ID: 33448710
Linux centos 5.3

0
 
LVL 32

Accepted Solution

by:
DrDamnit earned 1000 total points
ID: 33448746
Save all that stuff into file.sql, then:


mysql --user=user_name --password=your_password < file.sql

Open in new window

0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 4

Author Comment

by:jkockler
ID: 33449142
thanks!   Does it matter where I store that file, or do I specify the path in the command?
0
 
LVL 7

Assisted Solution

by:printnix63
printnix63 earned 1000 total points
ID: 33449421
Mysql runs as a deamon / service.
So, what you do with the above command, is, that you log on to your database service and tell it to "import" the sql script, i.e. the place where you start the command should be the place where you stored the file, or you have to provide the full path.

The database service will create it's files for the created database and tables.
What files and where had been defined in the mysql config files and the type of files depends on the type of database you are using (innoDB, myISAM, ...etc)

The sql script creates InnoDB and myISAM tables, so you will have different types of files in the location defined in the config file of mysql. - For the usage, you actually do not need to know where those files are located, as you "talk" to them only through the mysql service.


mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| asterisk           |
| .....              |
| mysql              |
| .......            |
| phpmyadmin         |
+--------------------+
nn rows in set (0.20 sec)

mysql> use asterisk;
Database changed
mysql> show tables;
+--------------------+
| Tables_in_asterisk |
+--------------------+
| cdr                |
| queue_members      |
| queues             |
| sip                |
| voicemail_messages |
| voicemail_users    |
+--------------------+
6 rows in set (0.00 sec)

mysql>

Open in new window

0
 
LVL 7

Assisted Solution

by:printnix63
printnix63 earned 1000 total points
ID: 33449509
So, to add on above example, you have a complete SQL script.
The SQL defines, what type of database(s) is/are to be created and
what type of tables and fields for the tables are to be created. This is all in your SQL file already.

The command line is only logging into the database with your user and password and telling mysql, to excecute the sql file (what I wrote above "to import")
This is actually creating the database + tables, as you can see from my snippet. (I just copied and pasted into an editor and ran
==================================
C:\tmp\mkmysql>mysql -uroot -p
Enter password: *******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.0.20-nt

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
==================================
Ok, my system is windows, but the mysql part is the same, and you can see, all is ready, when you execute the line.
0
 
LVL 4

Author Comment

by:jkockler
ID: 33450439
wow thanks a lot!!!!

So what do I type exactly from the command line:

I see
mysql>

I have tried
mysql>mysql.sql (the name of the file I stored)

and all I get is

mysql>mysql.sql
          ->
0
 
LVL 4

Author Comment

by:jkockler
ID: 33450466
well back up, I think I figured out the command portion... but I am getting this error:

ERROR 1396 at line 224: Operation CREATE USER failed for 'astrealtime'@'localhost'

Did you import the same file, and not get that error?
0
 
LVL 4

Author Comment

by:jkockler
ID: 33450705
nm, figured that out!  Thanks again for the help!  Just had to delete the db and restart the mysql service.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question