Install mysql5.5.12 in solaris10

Source: Internet
Author: User
Tags mysql host

Solaris10LowerMySQLInstallation and maintenance

MySQL is a very popular database system in open-source software. However, it cannot be started successfully when it is installed on Solaris according to the installation manual provided on the MySQL website. This article describes how to correctly install and start MySQL on Solaris 10.
Software and hardware environment:
* Sun5.10
* Solaris 10
* MySQL 5.5.12 (mysql-5.5.12-solaris10-sparc-64bit.pkg.gz)
Installation Method:
1. Download MySQL Community Server 5.1.12 (http://mysql.saudi.net.sa/Downloads/MySQL-5.5/mysql-5.5.12-solaris10-sparc-64bit.pkg.gz) from MySQL website)
2. After the download, upload it to the solairs system, for example:/export/home/test

3. Use the following command to decompress the installation package
# Gzip-D/export/home/test/mysql-5.5.12-solaris10-sparc-64bit.pkg.gz
4. Use the su command to become a Super User
Su-Root
5. Create a user group and user group for MySQL
# Groupadd MySQL
# Useradd-G MySQL
6. Use pkgadd to install the MySQL package
# Cd/export/home/test

# Pkgadd-D./mysql-5.5.12-solaris10-sparc-64bit.pkg.gz

The installation is shown as follows:

The following packages are available:

1 MySQL Community Server (GPL)

(Sun4u) 5.5.12

Select package (s) You wish to process (or 'all' to process

All packages). (default: All )[?,??, Q]:

The installed MySQL is located in the/opt/MySQL directory.
7, # cp/usr/local/MySQL/support-files/my-medium.cnf/etc/My. CNF

Copy the MySQL configuration file to/etc.

Modify the my. CNF file in the/etc directory. The content is as follows:
[Mysqld]
Basedir =/opt/MySQL
Datadir =/opt/MySQL/Data
Default-character-set = gb2312

[MySQL]

Default-character-set = gb2312

[Client]

Default-character-set = gb2312

8. Run the MySQL post-install file to create the database repository
# Cd/opt/MySQL
#./Scripts/mysql_install_db -- defaults-file =/etc/My. CNF -- user = MySQL &
# Chown-r root.
# Chown-r Mysql Data
# Chgrp-r mysql. (remember that the punctuation matches .)

// In the preceding steps, the MySQL user has only the permission for the data directory, and the permission for other directories is owned by the root user.
After these steps, you can start MySQL normally.
9. Start MySQL
# Cd/opt/MySQL
#./Bin/mysqld_safe -- defaults-file =/etc/My. CNF -- user = MySQL
You can also use the following method to start MySQL
#/Etc/init. d/MySQL start
10. change the password of the MySQL Root User
We recommend that you use the following command to change the password of the MySQL Root User when using MySQL for the first time:
#/Opt/MySQL/bin/mysqladmin-u Root Password 'new-password'
#/Opt/MySQL/bin/mysqladmin-u root-H hostname password 'new-password'
11. Stop a MySQL instance
#/Etc/init. d/MySQL stop

12. log on to MYSQL as the root user and SET network access permissions.

# Cd/opt/MySQL

#/Bin/MySQL-u root-P
Enter Password: (enter the password)

-U is followed by the user name.-P requires the password. Press enter and enter the password at the Enter password.
Mysql> grant all privileges on *. * To 'root' @ '%' with grant option;
// Grant data access permissions to any host
Mysql> flush privileges;
// The modification takes effect.
Mysql> exit;
// Exit the MySQL server

13. Modify the password of the root user

After logging on to MySQL (if you want to remotely connect successfully, this step is indispensable)

Mysql> set password for root = PASSWORD ('new _ password ');

Mysql> flush privileges;

Mysql> exit;

MySQLSeveral important Directories
After MySQL is installed, its database files, configuration files, and command files are not installed in the same directory as SQL Server by default. It is very important to understand these directories, especially for Linux beginners, the directory structure of Linux itself is complicated. If you cannot figure out the installation directory of MySQL, you won't be able to learn it in depth.
The following describes these directories.
1. Database directory
/Var/lib/MySQL/
2. Configuration File
/Usr/share/MySQL (MySQL. server command and configuration file)
3. Related commands
/Usr/bin (commands such as mysqladmin mysqldump)
4. Start the script
/Etc/rc. d/init. d/(directory for starting the script file MySQL)
5. Change the logon Password
MySQL does not have a password by default. It is self-evident that the password is added after installation.
1. Commands
Usr/bin/mysqladmin-u Root Password 'new-password'
Format: mysqladmin-u username-P old Password New Password
2. Example
Example 1: Add a 123456 password to the root user.
Type the following command:
[Root @ test1 local] #/usr/bin/mysqladmin-u Root Password 123456
Note: because the root account does not have a password at the beginning, the old-P password can be omitted.
3. test whether the modification is successful
1) login without a password
[Root @ test1 local] # MySQL
Error 1045: Access denied for user: 'root @ localhost' (using password: No)
An error is displayed, indicating that the password has been modified.
2) log on with the modified Password
[Root @ test1 local] # mysql-u root-P
Enter Password: (enter the password 123456 after modification)
Welcome to the MySQL monitor. commands end with; or/g.
Your MySQL connection ID is 4 to server version: 4.0.16-Standard
Type 'help; 'or'/H' for help. type'/C' to clear the buffer.
Mysql>
Successful!
You can use the mysqladmin command to change the password or the database to change the password.
6. Start and Stop
1. Start
After MySQL is installed, run the following command to start MySql in the/etc/init. d directory.
[Root @ test1 init. d] #/etc/init. d/MySQL start
2. Stop
/Usr/bin/mysqladmin-u root-P Shutdown
3. Automatic Start
1) Check whether MySQL is in the Auto Start List
[Root @ test1 local] #/sbin/chkconfig-list
2) Add MySQL to the startup Service Group of your system.
[Root @ test1 local] #/sbin/chkconfig-add MySQL
3) Delete MySQL from the startup Service Group.
[Root @ test1 local] #/sbin/chkconfig-del MySQL
VII. ChangesMySQLDirectory
The default data file storage directory of MySQL is/var/lib/MySQL. To move the directory to/home/data, perform the following steps:
1. Create a data directory under the Home Directory
CD/home
Mkdir data
2. Stop the MySQL service process:
Mysqladmin-u root-P Shutdown
3. Move the entire/var/lib/MySQL directory to/home/Data
MV/var/lib/MySQL/home/data/
In this way, the MySQL data file is moved to/home/data/MySQL.
4. Find the my. CNF configuration file.
If my. for the CNF configuration file, go to/usr/share/MySQL/and find *. copy one of the CNF files to/etc/and change it to my. CNF. The command is as follows:
[Root @ test1 MySQL] # cp/usr/share/MySQL/my-medium.cnf/etc/My. CNF
5. Edit the MySQL configuration file/etc/My. CNF.
To ensure that MySQL works properly, you must specify the location where the mysql. Sock file is generated. Change socket =/var/lib/MySQL. Sock to/home/MySQL. Sock. The procedure is as follows:
VI my. CNF (use the VI tool to edit the my. CNF file and find the following data to modify)
# The MySQL Server
[Mysqld]
Port = 3306
# Socket =/var/lib/MySQL. Sock)
Socket =/home/data/MySQL. Sock (add this line)
6. Modify the MySQL STARTUP script/etc/rc. d/init. d/MySQL
Finally, you need to modify the MySQL STARTUP script/etc/rc. d/init. d/MySQL: change the path on the Right of datadir =/var/lib/MySQL to your actual storage path: Home/data/MySQL.
[Root @ test1 etc] # vi/etc/rc. d/init. d/MySQL
# Datadir =/var/lib/MySQL (comment this row)
Datadir =/home/data/MySQL (add this row)
7. Restart the MySQL service.
/Etc/rc. d/init. d/MySQL start
Or use the reboot command to restart Linux.
If it works properly, it will succeed. Otherwise, check again against the previous seven steps.
8,MySQLCommon Operations
Note: Each Command in MySQL must end with a semicolon.
1. display the database
Mysql> show databases;
+ ---------- +
| Database |
+ ---------- +
| MySQL |
| Test |
+ ---------- +
2 rows in SET (0.04 Sec)
MySQL has just been installed with two databases: MySQL and test. The MySQL database is very important. It contains MySQL system information. We change the password and add new users. In fact, we use the relevant tables in this database for operations.
2. display tables in the database
Mysql> use MySQL; (open the database. to operate on each database, open the database, similar to FOXPRO)
Database changed
Mysql> show tables;
+ ----------------- +
| Tables_in_mysql |
+ ----------------- +
| Columns_priv |
| DB |
| Func |
| Host |
| Tables_priv |
| User |
+ ----------------- +
6 rows in SET (0.01 Sec)
3. display the data table structure:
Describe table name;
4. display the records in the table:
Select * from table name;
For example, the user table records in the MySQL database are displayed. All users who can operate on mysql users are in this table.
Select * from user;
5. database creation:
Create Database database name;
For example, create a database named aaa
Mysql> create databases AAA;
6. Create a table:
Use Database Name;
Create Table Name (field setting list );
For example, if you create a table name in the newly created AAA database, the table has four fields: ID (serial number, auto-increment), XM (name), Xb (gender), and csny (date of birth ).
Use AAA;
Mysql> Create Table Name (ID int (3) auto_increment not null primary key, XM char (8), XB char (2), csny date );
You can use the describe command to view the created table structure.
Mysql> describe name;
+ ------- + --------- + ------ + ----- + --------- + ---------------- +
| FIELD | type | null | key | default | extra |
+ ------- + --------- + ------ + ----- + --------- + ---------------- +
| ID | int (3) | pri | null | auto_increment |
| XM | char (8) | Yes | null |
| XB | char (2) | Yes | null |
| Csny | date | Yes | null |
+ ------- + --------- + ------ + ----- + --------- + ---------------- +
7. Add records
For example, add several related records.
Mysql> insert into name values ('', 'zhang san', 'mal', '2017-10-01 ');
Mysql> insert into name values ('', 'baiyun ', 'female', '2017-05-20 ');
The SELECT command can be used to verify the result.
Mysql> select * from name;
+ ---- + ------ + ------------ +
| ID | XM | XB | csny |
+ ---- + ------ + ------------ +
| 1 | Zhang San | male |
| 2 | Baiyun | female | 1972-05-20 |
+ ---- + ------ + ------------ +
8. Modify records
For example, change the date of birth of John
Mysql> Update name set csny = '2017-01-10 'Where XM = 'zhang san ';
9. delete records
For example, delete the records of Michael Jacob.
Mysql> Delete from name where XM = 'zhang san ';
10. Delete databases and tables
Drop database database name;
Drop table name;
9. AddMySQLUser
Format: grant select on database. * To username @ login host identified by "password"
Example 1: Add a user user_1 with a password of 123 so that he can log on to any host and have the permission to query, insert, modify, and delete all databases. First, use the root user to connect to MySQL, and then type the following command:
Mysql> grant select, insert, update, delete on *. * To user_1 @ "%" identified by "123 ";
In example 1, the added user is very dangerous. If you know the user_1 password, then he can log on to your MySQL database on any computer on the Internet and do whatever he wants. For the solution, see Example 2.
Example 2: Add a user_2 password of 123 so that the user can only log on to localhost, you can also query, insert, modify, and delete the database AAA (localhost refers to the local host, that is, the host where the MySQL database is located), so that the user knows the password of user_2, he cannot directly access the database from the Internet, and can only operate the AAA database through the MySQL host.
Mysql> grant select, insert, update, delete on AAA. * To user_2 @ localhost identified by "123 ";
If a new user cannot log on to MySQL, run the following command during logon:
Mysql-u user_1-p-h 192.168.113.50 (-H is followed by the IP address of the host to be logged on)
10. backup and recovery
1. Backup
For example, back up the AAA library created in the previous example to the back_aaa file.
[Root @ test1 root] # cd/home/data/MySQL (go to the database directory, this example library has been transferred from Val/lib/MySQL to/home/data/MySQL, see section 7 above)
[Root @ test1 MySQL] # mysqldump-u root-p -- opt AAA> back_aaa
2. Recovery
[Root @ test MySQL] # mysql-u root-p ccc <back_aaa

11. Remove database operation logs

The database will generate a lot of log files after working for a while, such as: mysql-bin.000001, mysql-bin.000002 ....

These files are large, and many of them have 1 GB.

1. Clear these log files.

# Cd/opt/MySQL

#/Bin/MySQL-u root-P
Enter Password: (enter the password)

Mysql> Reset master;

Mysql> exit;

2. No longer record these log files

Remove log-bin from my. CNF and restart the database.

UninstallMySQL
Root User execution
Pkgrm MySQL

-- Model: Sun v440 is pre-installed with solaris8 and reinstalled with 9. solaris9 comes with apache1.3 and the startup method.
/Usr/Apache/bin/apachectl start

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.