$ gtar xvf mysql-VERSION.tar
Now the untarred directory name is too long to handle [mysql-3.22.32-sun-solaris2.5.1-sparc] so for convenience you can rename it by using a move (mv) command:
$ mv mysql-3.22.32-sun-solaris2.5.1-sparc mysql-3.22.32
but this is optional, the installation will work without this also (but you will type more).
| #Default communication ports | |
| #MYSQL_TCP_PORT=3306 | #Change the port number for MySQL: you should use XXXXX+4 where XXXXX are the last 5 digits of the random number assigned to you when you joined this class. |
| if test -z "$MYSQL_UNIX_PORT" | |
| then | |
| MYSQL_UNIX_PORT="/tmp/mysql.sock" | #Change this to be somewhere in your unix
account directory path (for example
Use the result of the pwd command and attach mysql.sock, e.g. /auto/home-scf-22/csci571/MySQL/mysql-3.22.32/mysql.sock) |
| export MYSQL_UNIX_PORT | |
| fi | |
| #export MYSQL_TCP_PORT | |
| Make sure you uncomment the lines above in red(remove the ‘#’), and change both the TCP port to a number and the UNIX port to the file as explained above. |
$MYSQL =
"/YOUR_HOME_DIR_WHERE_MYSQL_IS_INSTALLED/bin/mysql"
Use the result of the pwd command for YOUR_HOME_DIR_WHERE_MYSQL_IS_INSTALLED, E.G.
/auto/home-scf-22/csci571/MySQL/mysql-3.22.32/bin/mysql
$ ./configure --prefix=ABSOLUTE_PATH_TO_YOUR_MYSQL_DIRECTORY
If everything went well, MySQL will actually start running, and you will get a message such as this one:
csci571.usc.edu(171): ./configure –-prefix=/auto/home-scf-22/csci571/MySQL/mysql-3.22.32
Creating db table
Creating host table
Creating user table
Creating func table
Creating tables_priv table
Creating columns_priv table
The latest information about MySQL is available on the web at http://www.mysql.com
Support MySQL by buying support/licenses at http://www.tcx.se/license.htmy.
Starting the mysqld server. You can test that it is up and running with the command:
./bin/mysqladmin version (Note: this command fails, but ignore it)
csci571.usc.edu(172): Starting mysqld daemon with databases from /auto/home-scf-22/csci571/MySQL/mysql-3.22.32/data
Note: If you do get an error, such as "mysqld daemon ended", move ahead anyway as in step 2 of "Running MySQL" (see below) you will again try to start the server.
$ ./scripts/mysql_install_db
This creates the user table which mySQL uses to control access to the databases that you create.
Running MySQL (only from csci571/csci571)
$ ./bin/mysqladmin -u root -S ~/mysql/mysql.sock -P PORT# -p version
You will be prompted for a password. Just type Enter with an "empty" password.
$ ./bin/mysqld --basedir=ABSOLUTE_PATH_TO_YOUR_MYSQL_DIRECTORY --log -P port# -u root
--datadir=ABSOLUTE_PATH_TO_YOUR_MYSQL_DIRECTORY/data --socket=ABSOLUTE_PATH_TO_YOUR_MYSQL_DIRECTORY/mysql.sock &
For example:
./bin/mysqld --basedir=/auto/home-scf-22/csci571/MySQL/mysql-3.22.32
--log -P 9004 -u root
--datadir=/auto/home-scf-22/csci571/MySQL/mysql-3.22.32/data
--socket=/auto/home-scf-22/csci571/MySQL/mysql-3.22.32/mysql.sock &
$ ./bin/mysql -u root -S ABSOLUTE_PATH_TO_YOUR_MYSQL_DIRECTORY/mysql.sock -p
or
$ ./bin/mysql -P YOUR-PORT# -u root --socket=/ABSOLUTE_PATH_TO_YOUR_MYSQL_DIRECTORY/mysql.sock
You will be prompted for a password. Just type Enter with an "empty" password.
Here is some sample output:
csci571.usc.edu(195): ./bin/mysql -u root -S /auto/home-scf-22/csci571/MySQL/mysql.sock -p
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 3.22.32
Type 'help' for help.
mysql>
To look at the user database, enter the following SQL statements:
use mysql
select * from user;
You should see something like the following (with a lot more columns actually displayed):
+---------------+------+------------------+-------------+-------------+------------- | Host | User | Password | Select_priv | Insert_priv | Update_priv +---------------+------+------------------+-------------+-------------+------------+ | localhost | root | 535c29643159d001 | Y | Y | Y | | csci571.usc.edu|root | | Y | Y | Y | | localhost | | | N | N | N | | csci571.usc.edu| | | N | N | N | +---------------+------+------------------+-------------+-------------+------------+
4 rows in set (0.02 sec)
This means that for the user root accessing mySQL from csci571.usc.edu, there is no password setup.
mysql>create database db1;
mysql>use db1;
mysql>create table tb1 (
name VARCHAR(20),
age INT
);
mysql>insert into tb1 values ('John', 20);
mysql>insert into tb1 values ('Mary', 25);
mysql>insert into tb1 values ('Tom', 24);
#!/auto/usc/perl/5.004/bin/perl
use DBI;
# Perform a select on csci571/db1 DBI;
$dbh=DBI->connect("dbi:mysql:db1:csci571.usc.edu:9004", "root","") || die $DBI::err;
#you may need to replace csci571.usc.edu and the port #
$sth=$dbh->prepare('SELECT * from tb1;');
$sth->execute;
print "Name\tAge\n";
print "-------\t--------------\n";
while (@row=$sth->fetchrow_array) {
print $row[0]."\t".$row[1]."\n";
}
$sth->finish;
$dbh->disconnect;
You can run the perl script and see the result
mysql>drop database db1;