1, create the relevant directory Users
| The code is as follows |
Copy Code |
Su–root Groupadd MySQL Useradd-g mysql-p xifenfei-s/bin/bash-m mysql-d/opt/mysql Mysql_base=/opt/mysql Mkdir-p $MYSQL _base/product/5.5 Mkdir-p $MYSQL _base/mysqldata Mkdir-p $MYSQL _base/mysqllog Mkdir-p/var/run/mysqld/ Chmod-r 777 $MYSQL _base Chown-r Mysql:mysql $MYSQL _base Chown-r Mysql:mysql/var/run/mysqld |
3. Environment variable Configuration
| The code is as follows |
Copy Code |
Export Mysql_base=/opt/mysql Export basedir= $MYSQL _base/product/5.5 Export datadir= $MYSQL _base/mysqldata Export Ld_library_path= $basedir/lib:/lib:/usr/lib:/usr/local/lib Export Tmpdir=/tmp Export Path=${path}:/usr/bin:/bin:/usr/bin/x11:/usr/local/bin Export path= $basedir: $basedir/bin:${path}: $LD _library_path |
4, adjust the MySQL user system restrictions (optional)
Edit file:/etc/security/limits.conf Add the following statement:
| The code is as follows |
Copy Code |
MySQL Soft nproc 2047 MySQL Hard Nproc 16384 MySQL Soft nofile 1024 MySQL Hard nofile 65536
|
Confirm that the following statement exists in/etc/pam.d/login, if it does not exist please increase:
Session Required Pam_limits.so
If the user shell is using Bourne, Bash, or Korn shell to modify/etc/profile, and add
The content. (On the SuSE operating system, you need to modify/etc/profile.local):
| The code is as follows |
Copy Code |
if [$USER = "MySQL"]; Then if [$SHELL = "/bin/ksh"]; Then Ulimit-p 16384 Ulimit-n 65536 Else Ulimit-u 16384-n 65536 Fi Fi |
5, the installation of the database
5.1 Extract the database to/opt/mysql/product/5.5
5.2) Installation Data
| The code is as follows |
Copy Code |
[Mysql@localhost ~]$ CD product/5.5/scripts/ [Mysql@localhost scripts]$./mysql_install_db–basedir= $basedir –datadir= $datadir –user=mysql |
5.3) Set MY.CNF parameters
| The code is as follows |
Copy Code |
| Vi/etc/my.cnf [Mysqladmin] Socket =/var/run/mysqld/mysqld.sock [Client] Port = 3306 Socket =/var/run/mysqld/mysqld.sock [Mysqld] Port = 3306 Socket =/var/run/mysqld/mysqld.sock user = MySQL Pid-file =/var/run/mysqld/mysqld.pid Basedir =/opt/mysql/product/5.5 DataDir =/opt/mysql/mysqldata skip-external-locking = 1 interactive_timeout = 1200 wait_timeout = 1200 Character-set-server = UTF8 Back_log = 500 Default_time_zone = ' +08:00 ' max_connections = 1000 max_connect_errors = 1000 Connect_timeout = 300 Table_open_cache = 100 Max_allowed_packet = 16M Binlog_cache_size = 8M Max_heap_table_size = 64M Sort_buffer_size = 8M Join_buffer_size = 8M Thread_cache_size = 32 Thread_concurrency = 16 Query_cache_size = 0M Default-storage-engine = INNODB Thread_stack = 192K Transaction_isolation = read-committed Tmp_table_size = 64M Log-bin =/opt/mysql/mysqllog/mysqlbin Log-error=/opt/mysql/mysqllog/mysqld.err Expire_logs_days = 7 Binlog_format = ROW Max_binlog_size = 300M Slow_query_log = 1 Slow_query_log_file =/opt/mysql/mysqllog/mysqld-slow Long_query_time = 10 Tmpdir =/tmp Server-id = 1 Key_buffer_size = 8M Read_buffer_size = 1M Read_rnd_buffer_size = 1M Bulk_insert_buffer_size = 1M Myisam_sort_buffer_size = 128K Innodb_additional_mem_pool_size = 16M Innodb_buffer_pool_size = 2G Innodb_data_file_path = Ibdata1:1024m:autoextend Innodb_autoextend_increment = 64 innodb_file_per_table = 1 Innodb_data_home_dir =/opt/mysql/mysqldata Innodb_file_io_threads = 4 Innodb_thread_concurrency = 16 Innodb_flush_log_at_trx_commit = 2 Innodb_log_buffer_size = 8M Innodb_log_file_size = 512M Innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 40 Innodb_lock_wait_timeout = 120 Innodb_locks_unsafe_for_binlog = 1 Innodb_autoinc_lock_mode = 2 Skip-name-resolve Lower_case_table_names=1 [Mysqldump] Quick Max_allowed_packet = 16M [MySQL] Auto-rehash [Myisamchk] Key_buffer_size = 512M Sort_buffer_size = 512M Read_buffer = 8M Write_buffer = 8M [Mysqlhotcopy] Interactive-timeout [Mysqld_safe] Open-files-limit = 8192 |
5.4) Exception Handling
5.4.1) can not start the database directly through Mysqld_safe
| The code is as follows |
Copy Code |
Ln-s/opt/mysql/product/5.5/usr/local/mysql Or Ln-s/opt/mysql/product/5.5/bin/mysqld/usr/local/mysql/bin/mysqld |
5.4.2) Mysql_secure_installation not performing properly
1)
Execution:/opt/mysql/product/5.5/bin/mysql_secure_installation The following error occurred, workaround (Ln-s/var/run/mysqld/mysqld.sock/tmp/ Mysql.sock)
Enter current password for root (enter for none):
ERROR 2002 (HY000): Can ' t connect to the local MySQL server through socket '/tmp/mysql.sock ' (2)
2)
Modify the Do_query function of the mysql_secure_installation script (recommended processing method)
| The code is as follows |
Copy Code |
Do_query () { echo "$1″> $command #sed ' s,^,>, ' < $command # debugging # mysql--defaults-file= $config < $command----This row is modified as follows: MySQL--defaults-extra-file= $config < $command Return $? } |
6. Add Boot Service
modifying Mysql.server files
| code is as follows |
copy code |
basedir=/opt/ mysql/product/5.5 Datadir=/opt/mysql/mysqldata [root@localhost ~]# cp/opt/mysql/product/5.5/support-files/ Mysql.server/etc/init.d/mysqld [root@localhost ~]# chkconfig–add mysqld [root@localhost ~]# chkconfig-mysqld on [root@localhost ~]# chkconfig–list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off |