一、mysql有三种安装方式
1、rpm包形式。2、通用二进制形式。3、源码编译 rpm包下载地址http://dev.mysql.com/downloads/mysql/ 选择相应平台,可下载MySQL-5.6.22-1.rhel5.i386.rpm-bundle.tar版本,包含七个文件 MySQL-client 客户端组件 MySQL-server 服务端组件 MySQL-debuginfo 调试MySQL的组件 MySQL-devel 想针对于MySQL编译安装PHP等依赖于MySQL的组件包 MySQL-embedded MySQL的嵌入式版本 MySQL-shared 共享库 MySQL-shared-dompat 为了兼容老版本的共享库 MySQL-test MySQL的测试组件(在线处理功能 通用二进制形式:下载地址http://dev.mysql.com/downloads/mysql/ ,平台选择Linux - Generic 源码编译:下载地址http://dev.mysql.com/downloads/mysql/ ,平台选择Source Code
二、初学选择RPM包安装方式,下载-上传-解压-安装
[root@fyl Mysql]# tar -xvf MySQL-5.6.22-1.rhel5.i386.rpm-bundle.tar MySQL-devel-5.6.22-1.rhel5.i386.rpm MySQL-shared-5.6.22-1.rhel5.i386.rpm MySQL-shared-compat-5.6.22-1.rhel5.i386.rpm MySQL-server-5.6.22-1.rhel5.i386.rpm MySQL-client-5.6.22-1.rhel5.i386.rpm MySQL-embedded-5.6.22-1.rhel5.i386.rpm MySQL-test-5.6.22-1.rhel5.i386.rpm
1)安装服务端 [root@fyl Mysql]# rpm -ivh MySQL-server-5.6.22-1.rhel5.i386.rpm Preparing... ########################################### [100%] 1:MySQL-server ########################################### [100%] warning: user mysql does not exist - using root warning: group mysql does not exist - using root 2015-03-27 12:40:06 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2015-03-27 12:40:06 2861 [Note] InnoDB: Using mutexes to ref count buffer pool pages 2015-03-27 12:40:06 2861 [Note] InnoDB: The InnoDB memory heap is disabled 2015-03-27 12:40:06 2861 [Note] InnoDB: Mutexes and rw_locks use InnoDB's own implementation 2015-03-27 12:40:06 2861 [Note] InnoDB: Memory barrier is not used 2015-03-27 12:40:06 2861 [Note] InnoDB: Compressed tables use zlib 1.2.3 2015-03-27 12:40:06 2861 [Note] InnoDB: Using Linux native AIO 2015-03-27 12:40:06 2861 [Note] InnoDB: Not using CPU crc32 instructions 2015-03-27 12:40:06 2861 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2015-03-27 12:40:06 2861 [Note] InnoDB: Completed initialization of buffer pool 2015-03-27 12:40:06 2861 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created! 2015-03-27 12:40:06 2861 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB 2015-03-27 12:40:06 2861 [Note] InnoDB: Database physically writes the file full: wait... 2015-03-27 12:40:08 2861 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB 2015-03-27 12:40:11 2861 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB 2015-03-27 12:40:13 2861 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 2015-03-27 12:40:13 2861 [Warning] InnoDB: New log files created, LSN=45781 2015-03-27 12:40:13 2861 [Note] InnoDB: Doublewrite buffer not found: creating new 2015-03-27 12:40:13 2861 [Note] InnoDB: Doublewrite buffer created 2015-03-27 12:40:13 2861 [Note] InnoDB: 128 rollback segment(s) are active. 2015-03-27 12:40:13 2861 [Warning] InnoDB: Creating foreign key constraint system tables. 2015-03-27 12:40:13 2861 [Note] InnoDB: Foreign key constraint system tables created 2015-03-27 12:40:13 2861 [Note] InnoDB: Creating tablespace and datafile system tables. 2015-03-27 12:40:13 2861 [Note] InnoDB: Tablespace and datafile system tables created. 2015-03-27 12:40:13 2861 [Note] InnoDB: Waiting for purge to start 2015-03-27 12:40:13 2861 [Note] InnoDB: 5.6.22 started; log sequence number 0 A random root password has been set. You will find it in '/root/.mysql_secret'. 2015-03-27 12:40:13 2861 [Note] Binlog end 2015-03-27 12:40:13 2861 [Note] InnoDB: FTS optimize thread exiting. 2015-03-27 12:40:13 2861 [Note] InnoDB: Starting shutdown... 2015-03-27 12:40:15 2861 [Note] InnoDB: Shutdown completed; log sequence number 1625977 2015-03-27 12:40:15 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2015-03-27 12:40:15 2883 [Note] InnoDB: Using mutexes to ref count buffer pool pages 2015-03-27 12:40:15 2883 [Note] InnoDB: The InnoDB memory heap is disabled 2015-03-27 12:40:15 2883 [Note] InnoDB: Mutexes and rw_locks use InnoDB's own implementation 2015-03-27 12:40:15 2883 [Note] InnoDB: Memory barrier is not used 2015-03-27 12:40:15 2883 [Note] InnoDB: Compressed tables use zlib 1.2.3 2015-03-27 12:40:15 2883 [Note] InnoDB: Using Linux native AIO 2015-03-27 12:40:15 2883 [Note] InnoDB: Not using CPU crc32 instructions 2015-03-27 12:40:15 2883 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2015-03-27 12:40:15 2883 [Note] InnoDB: Completed initialization of buffer pool 2015-03-27 12:40:15 2883 [Note] InnoDB: Highest supported file format is Barracuda. 2015-03-27 12:40:15 2883 [Note] InnoDB: 128 rollback segment(s) are active. 2015-03-27 12:40:15 2883 [Note] InnoDB: Waiting for purge to start 2015-03-27 12:40:15 2883 [Note] InnoDB: 5.6.22 started; log sequence number 1625977 2015-03-27 12:40:15 2883 [Note] Binlog end 2015-03-27 12:40:15 2883 [Note] InnoDB: FTS optimize thread exiting. 2015-03-27 12:40:15 2883 [Note] InnoDB: Starting shutdown... 2015-03-27 12:40:16 2883 [Note] InnoDB: Shutdown completed; log sequence number 1625987 A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER ! You will find that password in '/root/.mysql_secret'. You must change that password on your first connect, no other statement but 'SET PASSWORD' will be accepted. See the manual for the semantics of the 'password expired' flag. Also, the account for the anonymous user has been removed. In addition, you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test database. This is strongly recommended for production servers. See the manual for more instructions. Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com New default config file was created as /usr/my.cnf and will be used by default by the server when you start it. You may edit this file to change server settings 安装完默认产生mysql用户 [root@fyl Mysql]# id mysql uid=101(mysql) gid=104(mysql) groups=104(mysql) 开启mysql服务 [root@fyl Mysql]# service mysql start Starting MySQL.[ OK ] [root@fyl Mysql]# ps -fu mysql UID PID PPID C STIME TTY TIME CMD mysql 3090 3089 0 12:43 pts/2 00:00:00 -bash mysql 3253 3150 6 12:48 pts/1 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/va [root@fyl Mysql]# netstat -an | grep 3306 ----mysql默认端口3306 tcp 0 0 :::3306 :::* LISTEN 安装客户端 [root@fyl Mysql]# rpm -ivh MySQL-client-5.6.22-1.rhel5.i386.rpm Preparing... ########################################### [100%] 1:MySQL-client ########################################### [100%]三、登录验证
-bash-3.2$ mysql -u root -p Enter password: --安装过程随机生成,在文件/root/.mysql_secret [root@fyl Mysql]# cat /root/.mysql_secret # The random password set for the root user at Fri Mar 27 12:40:13 2015 (local time): 5w3BxVJOWqhz545x mysql> show databases; ERROR 1820 (HY000): You must SET PASSWORD before executing this statement mysql> SET PASSWORD = PASSWORD('mysql'); Query OK, 0 rows affected (0.00 sec) 退出用新密码验证 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec)四、MySQL的几个重要目录
1、数据库目录 /var/lib/mysql/ 日志文件,数据库 2、配置文件 /usr/share/mysql(mysql.server命令及配置文件) 错误消息和字符集文件 3、相关命令 /usr/bin(mysqladmin mysqldump等命令) 客户端程序、脚本 4、启动脚本 /etc/rc.d/init.d/(启动脚本文件mysql的目录) 如:/etc/rc.d/init.d/mysql start/restart/stop/status五、更改MySQL目录
MySQL默认的数据文件存储目录为/var/lib/mysql。假如要把目录移到/u01/mysql下需要进行下面几步: 1、建立目录 2、把MySQL服务进程停掉: [root@fyl Mysql]# mysqladmin -u root -p shutdown Enter password: 3、把/var/lib/mysql整个目录移到/u01/ [root@fyl lib]# pwd /var/lib [root@fyl lib]# cp -a mysql /u01/ 4、修改/etc/rc.d/init.d/mysql的datadir目录值,修改结果如: [root@fyl etc]# vi /etc/rc.d/init.d/mysql basedir= datadir=/u01/mysql 修改/usr/bin/mysqld_safe的datadir的目录值 [root@fyl lib]#vi /usr/bin/mysqld_safe 注释掉之前的代码 #DATADIR=/var/lib/mysql 修改为: DATADIR=/u01/mysql 5、配置my.cnf文件 该版本安装完没有/etc/my.cnf和/usr/share/mysql/my-medium.cnf直接 vi /etc/my.cnf [root@fyl etc]# cat my.cnf [client] #password = your_password port = 3306 socket = /u01/mysql/mysql.sock default-character-set=utf8 [mysqld] port = 3306 socket = /u01/mysql/mysql.sock skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M character_set_server=utf8 collation-server=utf8_general_ci lower_case_table_names=1 character_set_client=utf8 [mysql] no-auto-rehash # Remove the next comment character if you are not familiar with SQL #safe-updates [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout [root@fyl etc]# 原/usr/share/mysql/下有好几个结尾为cnf的文件,它们的作用分别是: 5.1.my-small.cnf是为了小型数据库而设计的。不应该把这个模型用于含有一些常用项目的数据库。 5.2.·my-medium.cnf是为中等规模的数据库而设计的。如果你正在企业中使用RHEL,可能会比这个操作系统的最小RAM需求(256MB)明显多得多的物理内存。由此可见,如果有那么多RAM内存可以使用,自然可以在同一台机器上运行其它服务。 5.3·my-large.cnf是为专用于一个SQL数据库的计算机而设计的。由于它可以为该数据库使用多达512MB的内存,所以在这种类型的系统上将需要至少1GB的RAM,以便它能够同时处理操作系统与数据库应用程序。 5.4·my-huge.cnf是为企业中的数据库而设计的。这样的数据库要求专用服务器和1GB或1GB以上的RAM。 这些选择高度依赖于内存的数量、计算机的运算速度、数据库的细节大小、访问数据库的用户数量以及在数据库中装入并访问数据的用户数量。随着数据库和用户的不断增加,数据库的性能可能会发生变化。 6、需要建立一个mysql.sock的链接: ln -s /u01/mysql/mysql.sock /var/lib/mysql/mysql.sock 7、验证 [root@fyl mysql]# service mysql start Starting MySQL.[ OK ] [root@fyl mysql]# service mysql stop Shutting down MySQL..[ OK ]