Install MySQL database in Unix
We recommend that you create a user and group for MySQL management during installation. This group of users runs the mysql server and executes management tasks. (You can also run the server as root, but it is not recommended)
Step 1 create a user to run the server. In Solaris and unix, you can use useradd and groupadd tools. Name it mysql. (Of course, any id you like) so before doing other things, use the su command to become root:
$ Su-root
$ Groupadd mysql
$ Useradd-g mysql
Select the location where you want to install the mysql software and convert the current directory to this directory. Generally, install it to/usr/local, which is the standard installation location of MySQL software. Go in now,
$ Cd/usr/local
Unpack the software package:
$ Gunzip-c/tmp/mysql -3.23.xx.tar.gz | tar-xf-
Because it is installed on the Solaris server, if tar of different versions, such as GNU tar, is installed, the above command will not work. Use the following command:
$ Gunzip-c/tmp/mysql -3.23.xx.tar.gz | gtar-xf-
Now you can check the new directory to see if it exists.
$ Ls-ld mysql *
Total 1
Drwxr-xr-x 28 user 1024 Jul 18 mysql-3.23.x/
The next step is to create a symbolic link so that the installation can point to/usr/local/mysql:
$ Ln-s mysql-3.23.x mysql
$ Ls-ld mysql *
The connection is successful. After the software is installed, several configuration tasks need to be completed. Run scripts/mysql_install_db to create the MySQL license table:
$ Scripts/mysql_install_db
Preparing db talbe
Preparing host table
Preparing user table
Preparing func table
Preparing tables_priv table
Preparing columns_priv table
Installing all prepared tables
010726 19:40:05./bin/mysqld: Shutdown Complete
Set the ownership of the binary file, so that it belongs to the root, and belongs to the MySQL
Administrator group (mysql in this example)
$ Chown-R root/usr/local/mysql
$ Chgrp-R mysql/usr/local/mysql
Set the ownership of the data directory to the MySQL administrator created earlier.
$ Chown-R mysql/usr/local/mysql/data
Ownership settings complete
To start the server, run safe_mysqld:
$ Bin/safe_mysqld -- usr = mysql &
MySQL is usually required to run during server boot. To this end, you can copy support-files/mysql. server to the appropriate system location.
To ensure that MySQL works properly, you need to run some simple tests. if the output result is BINDIR =/usr/local/mysql/bin, it indicates that MySQL works normally. the value of BINDIR is related to the prefix option selected above.
--------------------------------------------------------------------------------
# BINDIR/mysqlshow-p
+ --------------- +
| Databases |
+ --------------- +
| Mysql |
+ --------------- +
--------------------------------------------------------------------------------
Once you install MySQL, it will automatically generate two databases. One is used to manage user, host, and Server Database permissions. The other is test database ). We can use the test database. However, we want to give you a brief overview of some of the available commands in MySQL. This also ensures that the root user can be set to have full access to the server. for example, root can allow the user to create databases and forms. Therefore, we will create a test2 database for future testing. Before entering MySQL through commands, the system will prompt you to enter the newly created root password. Remember that you have changed the root password.
--------------------------------------------------------------------------------
# Mysql-u root-p
Mysql> show databases;
+ ---------------- +
| Database |
+ ---------------- +
| Mysql |
| Test |
+ ---------------- +
Mysql> create database test2;
Query OK, 1 row affected (0.00 sec)
--------------------------------------------------------------------------------
Use the following two pieces of code to select a new database and create a table named tst_tbl. It has two fields. The first field (field 1) is the id field, through which you can see the id of the record. Essentially, this is only a column of pure numbers. The second field is the name field, in which the name of the book can be stored. The format of these fields is: field 1 (id) is an integer (int) with a length of 3, and field 2 (name) is a string (char) with a length of 50 ). We can assign values to IDS to search and index data.
--------------------------------------------------------------------------------
Mysql> use test2;
Database changed
Mysql> create table books (id int (3) not null
-> Auto_increment, name char (50) not null,
-> Unique (id), primary key (id ));
Query OK, 0 rows affected (0.00 sec)
--------------------------------------------------------------------------------
Run the following command to check whether the database is correct.
--------------------------------------------------------------------------------
Mysql> show tables;
+ --------------------- +
| Tables in test2 |
+ --------------------- +
| Books |
+ --------------------- +
1 row in set (0.00 sec)
Mysql> describe books;
+ ------- + ------------- + ------ + ---------- + ---------------- +
| Field | Type | Null | Key | Default | Extra |
+ ------- + ------------- + ------ + ---------- + ---------------- +
| Id | int (3) | PRI | 0 | auto_increment |
| Name | char (50) |
+ ------- + ------------- + ------ + ---------- + ---------------- +
2 rows in set (0.00 sec)
--------------------------------------------------------------------------------
Note: The describe command basically depicts the table layout.
OK. The following describes some useful SQL commands: how to insert and select data in the database. You can add several records to the new table.
--------------------------------------------------------------------------------
Mysql> insert into books (name) values (PHP 4 Newbies );
Query OK, 1 row affected (0.00 sec)
Mysql> insert into books (name) values (Red Hat Linux 6 Server );
Query OK, 1 row affected (0.00 sec)
--------------------------------------------------------------------------------
Check the new record and familiarize yourself with the select command.
-------------------------------------------------------------------------------
Mysql> SELECT * from books;
+ ---- + ------------------------------------ +
| Id | name |
+ ---- + ------------------------------------ +
| 1 | PHP for Newbies |
| 2 | Red Hat Linux 6 Server |
+ ---- + ------------------------------------ +
2 rows in set (0.00 sec)
--------------------------------------------------------------------------------
In this way, the MySQL server can run normally. We can continue to add records, but there is no more significance here.
Note: You do not need to specify an id when inserting records into the database. This is because the id field you created has the option automatically added.
The following describes how to quickly delete an object. It just gives you a simple piece of information, remembering that you can find all the mysql commands and server information you want on the mysql web site http://www.mysql.com.
--------------------------------------------------------------------------------
Mysql> delete from books where id = 1;
Query OK, 1 row affected (0.00 sec)
Mysql> select * from books;
+ ---- + ------------------------------------- +
| Id | name |
+ ---- + ------------------------------------- +
| 2 | Red Hat Linux 6 Server |
+ ---- + ------------------------------------- +
1 row in set (0.00 sec)