Mysql5.5安装

1.解决perl编译环境问题:

#echo 'export LC_ALL=C'>>/etc/profile
#source /etc/profile

2.安装必须的组件包:

#yum groupinstall -y "Base" ,"Compatibilitylibraries","Hardware monitoring utilities","DebuggingTools","Dial-up Networking Support","Developmenttools"
#yum install -y  cmake ncurses*

3.添加用户和组:

#groupadd mysql
#useradd mysql -g mysql -M -s /sbin/mysql

4.创建mysql的目录:

#mkdir /application/mysql �Cp

5.修改环境变量:

#echo'PATH=$PATH:/application/mysql/bin'>>/etc/profile
#source /etc/profile

6.开始安装:

#tar xf mysql-5.5.47.tar.gz
#cd mysql-5.5.47
#cmake .-DCMAKE_INSTALL_PREFIX=/application/mysql \
-DMYSQL_DATADIR=/application/mysql/data \
-DMYSQL_UNIX_ADDR=/application/mysql/mysql.sock\
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
make&&make install

7.初始化数据库:

#/application/mysql/scripts/mysql_install_db  --user=mysql--datadir=/application/mysql/data   --basedir=/application/mysql

8.添加mysql的配置文件:

#vim /etc/my.cnf
[client]
port            = 3306
socket          = /application/mysql/mysql.sock
 
[mysql]
no-auto-rehash
 
[mysqld]
user   = mysql
port   = 3306
socket = /application/mysql/mysql.sock
basedir = /application/mysql
datadir = /application/mysql/data
open_files_limit    = 1024
back_log = 600
max_connections = 800
max_connect_errors = 3000
table_cache = 614
external-locking = FALSE
max_allowed_packet =8M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 100
thread_concurrency = 2
query_cache_size = 2M
query_cache_limit = 1M
query_cache_min_res_unit = 2k
#default_table_type = InnoDB
thread_stack = 192K
#transaction_isolation = READ-COMMITTED
tmp_table_size = 2M
max_heap_table_size = 2M
long_query_time = 1
#log_long_format
#log-error = /application/mysql/error.log
#log-slow-queries =/application/mysql/slow.log
pid-file = /application/mysql/mysql.pid
log-bin = /application/mysql/mysql-bin
relay-log = /application/mysql/relay-bin
relay-log-info-file =/application/mysql/relay-log.info
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
expire_logs_days = 7
key_buffer_size = 16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
#myisam_sort_buffer_size = 1M
#myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
#myisam_repair_threads = 1
#myisam_recover
 
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors = 1032,1062
replicate-ignore-db=mysql
 
server-id = 1
 
innodb_additional_mem_pool_size = 4M
innodb_buffer_pool_size = 32M
innodb_data_file_path =ibdata1:128M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 4M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
max_allowed_packet = 2M
 
[mysqld_safe]
log-error=/application/mysql/mysql_3306.err
pid-file=/application/mysql/mysqld.pid
:x

 

9.添加mysql的启动脚本:

#vim /etc/init.d/mysqld
# chkconfig: 2345 64 36
#init
mysql_user="root"
mysql_pwd="abc-123"
CmdPath="/application/mysql/bin"
mysql_sock="/application/mysql/mysql.sock"
#startup function
function_start_mysql()
{
   if [ ! -e "$mysql_sock" ];then
     printf "Starting MySQL...\n"
     /bin/sh ${CmdPath}/mysqld_safe --defaults-file=/etc/my.cnf 2>&1> /dev/null &
   else
     printf "MySQL is running...\n"
     exit
   fi
}
 
#stop function
function_stop_mysql()
{
   if [ ! -e "$mysql_sock" ];then
      printf "MySQL is stopped...\n"
      exit
   else
      printf "Stoping MySQL...\n"
      ${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd}  shutdown
   fi
}
 
#restart function
function_restart_mysql()
{
   printf "Restarting MySQL...\n"
   function_stop_mysql
   sleep 2
   function_start_mysql
}
 
case $1 in
start)
   function_start_mysql
;;
stop)
   function_stop_mysql
;;
restart)
   function_restart_mysql
;;
*)
   printf "Usage: /etc/init.d/mysqld {start|stop|restart}\n"
esac
:x

 

#chmod +x /etc/init.d/mysqld
#chkconfig --add mysqld
#chkconfig mysqld on
#service mysqld start

 

10.启动后,基本优化:

添加密码:

#mysqladmin �Curoot password  ‘abc-123’

修改密码:

#mysqladmin �Curoot �Cpabc-123 password ‘abcd-1234’

删除不必要的用户:

mysql>select user,host from mysql.user;
mysql>drop user ‘’@’localhost’;


你可能感兴趣的:(mysql)