mysql 是最流行的关系型数据库管理系统,由瑞典mysql ab公司开发,目前属于oracle公司。
mysql所使用的sql语言是用于访问数据库的最常用标准化语言。
mysql由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型网站的开发都选择mysql作为网站数据库。
mysql 安装
本教程的系统平台:centos release 6.6 (final) 64位。
一、安装编译工具及库文件
yum -y install gcc gcc-c make autoconf libtool-ltdl-devel gd-devel freetype-devel libxml2-devel libjpeg-devel libpng-devel openssl-devel curl-devel bison patch unzip libmcrypt-devel libmhash-devel ncurses-devel sudo bzip2 flex libaio-devel
二、 安装cmake 编译器
cmake 版本:cmake-3.1.1。
1、下载地址:
$ wget http://www.cmake.org/files/v3.1/cmake-3.1.1.tar.gz
2、解压安装包
$ tar zxvf cmake-3.1.1.tar.gz
3、进入安装包目录
$ cd cmake-3.1.1
4、编译安装
$ ./bootstrap $ make && make install
三、安装 mysql
mysql版本:mysql-5.6.15。
1、下载地址:
$ wget http://dev.mysql.com/get/downloads/mysql-5.6/mysql-5.6.15.tar.gz
2、解压安装包
$ tar zxvf mysql-5.6.15.tar.gz
3、进入安装包目录
$ cd mysql-5.6.15
4、编译安装
$ cmake -dcmake_install_prefix=/usr/local/webserver/mysql/ -dmysql_unix_addr=/tmp/mysql.sock -ddefault_charset=utf8 -ddefault_collation=utf8_general_ci -dwith_extra_charsets=all -dwith_myisam_storage_engine=1 -dwith_innobase_storage_engine=1 -dwith_memory_storage_engine=1 -dwith_readline=1 -dwith_innodb_memcached=1 -dwith_debug=off -dwith_zlib=bundled -denabled_local_infile=1 -denabled_profiling=on -dmysql_maintainer_mode=off -dmysql_datadir=/usr/local/webserver/mysql/data -dmysql_tcp_port=3306 $ make && make install
5、查看mysql版本:
$ /usr/local/webserver/mysql/bin/mysql --version
到此,mysql安装完成。
mysql 配置
1、创建mysql运行使用的用户mysql:
$ /usr/sbin/groupadd mysql $ /usr/sbin/useradd -g mysql mysql
2、创建binlog和库的存储路径并赋予mysql用户权限
$ mkdir -p /usr/local/webserver/mysql/binlog /www/data_mysql
$ chown mysql.mysql /usr/local/webserver/mysql/binlog/ /www/data_mysql/
3、创建my.cnf配置文件
将/etc/my.cnf替换为下面内容
$ cat /etc/my.cnf [client] port = 3306 socket = /tmp/mysql.sock [mysqld] replicate-ignore-db = mysql replicate-ignore-db = test replicate-ignore-db = information_schema user = mysql port = 3306 socket = /tmp/mysql.sock basedir = /usr/local/webserver/mysql datadir = /www/data_mysql log-error = /usr/local/webserver/mysql/mysql_error.log pid-file = /usr/local/webserver/mysql/mysql.pid open_files_limit = 65535 back_log = 600 max_connections = 5000 max_connect_errors = 1000 table_open_cache = 1024 external-locking = false max_allowed_packet = 32m sort_buffer_size = 1m join_buffer_size = 1m thread_cache_size = 600 #thread_concurrency = 8 query_cache_size = 128m query_cache_limit = 2m query_cache_min_res_unit = 2k default-storage-engine = myisam default-tmp-storage-engine=myisam thread_stack = 192k transaction_isolation = read-committed tmp_table_size = 128m max_heap_table_size = 128m log-slave-updates log-bin = /usr/local/webserver/mysql/binlog/binlog binlog-do-db=oa_fb binlog-ignore-db=mysql binlog_cache_size = 4m binlog_format = mixed max_binlog_cache_size = 8m max_binlog_size = 1g relay-log-index = /usr/local/webserver/mysql/relaylog/relaylog relay-log-info-file = /usr/local/webserver/mysql/relaylog/relaylog relay-log = /usr/local/webserver/mysql/relaylog/relaylog expire_logs_days = 10 key_buffer_size = 256m read_buffer_size = 1m read_rnd_buffer_size = 16m bulk_insert_buffer_size = 64m myisam_sort_buffer_size = 128m myisam_max_sort_file_size = 10g myisam_repair_threads = 1 myisam_recover interactive_timeout = 120 wait_timeout = 120 skip-name-resolve #master-connect-retry = 10 slave-skip-errors = 1032,1062,126,1114,1146,1048,1396 #master-host = 192.168.1.2 #master-user = username #master-password = password #master-port = 3306 server-id = 1 loose-innodb-trx=0 loose-innodb-locks=0 loose-innodb-lock-waits=0 loose-innodb-cmp=0 loose-innodb-cmp-per-index=0 loose-innodb-cmp-per-index-reset=0 loose-innodb-cmp-reset=0 loose-innodb-cmpmem=0 loose-innodb-cmpmem-reset=0 loose-innodb-buffer-page=0 loose-innodb-buffer-page-lru=0 loose-innodb-buffer-pool-stats=0 loose-innodb-metrics=0 loose-innodb-ft-default-stopword=0 loose-innodb-ft-inserted=0 loose-innodb-ft-deleted=0 loose-innodb-ft-being-deleted=0 loose-innodb-ft-config=0 loose-innodb-ft-index-cache=0 loose-innodb-ft-index-table=0 loose-innodb-sys-tables=0 loose-innodb-sys-tablestats=0 loose-innodb-sys-indexes=0 loose-innodb-sys-columns=0 loose-innodb-sys-fields=0 loose-innodb-sys-foreign=0 loose-innodb-sys-foreign-cols=0 slow_query_log_file=/usr/local/webserver/mysql/mysql_slow.log long_query_time = 1 [mysqldump] quick max_allowed_packet = 32m
4、初始化数据库
$/usr/local/webserver/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql
显示如下信息:
installing mysql system tables...2015-01-26 20:18:51 0 [warning] timestamp with implicit default value is deprecated. please use --explicit_defaults_for_timestamp server option (see documentation for more details).
ok
filling help tables...2015-01-26 20:18:57 0 [warning] timestamp with implicit default value is deprecated. please use --explicit_defaults_for_timestamp server option (see documentation for more details).
ok
...
5、创建开机启动脚本
$ cd /usr/local/webserver/mysql/ $ cp support-files/mysql.server /etc/rc.d/init.d/mysqld $ chkconfig --add mysqld $ chkconfig --level 35 mysqld on
6、启动mysql服务器
$ service mysqld start
7、连接 mysql
$ /usr/local/webserver/mysql/bin/mysql -u root -p
修改mysql用户密码
mysqladmin -u用户名 -p旧密码 password 新密码
或进入mysql命令行
set password for '用户名'@'主机' = password(‘密码');
创建新用户并授权:
grant all privileges on *.* to 用户名@'%' identified by '密码' with grant option;
其他命令
-
启动:service mysqld start
-
停止:service mysqld stop
-
重启:service mysqld restart
-
重载配置:service mysqld reload