linux下安装mysql

来源:互联网 发布:java规则引擎源码 编辑:程序博客网 时间:2024/04/28 07:12

一、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.rpmMySQL-shared-5.6.22-1.rhel5.i386.rpmMySQL-shared-compat-5.6.22-1.rhel5.i386.rpmMySQL-server-5.6.22-1.rhel5.i386.rpmMySQL-client-5.6.22-1.rhel5.i386.rpmMySQL-embedded-5.6.22-1.rhel5.i386.rpmMySQL-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 rootwarning: group mysql does not exist - using root2015-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 pages2015-03-27 12:40:06 2861 [Note] InnoDB: The InnoDB memory heap is disabled2015-03-27 12:40:06 2861 [Note] InnoDB: Mutexes and rw_locks use InnoDB's own implementation2015-03-27 12:40:06 2861 [Note] InnoDB: Memory barrier is not used2015-03-27 12:40:06 2861 [Note] InnoDB: Compressed tables use zlib 1.2.32015-03-27 12:40:06 2861 [Note] InnoDB: Using Linux native AIO2015-03-27 12:40:06 2861 [Note] InnoDB: Not using CPU crc32 instructions2015-03-27 12:40:06 2861 [Note] InnoDB: Initializing buffer pool, size = 128.0M2015-03-27 12:40:06 2861 [Note] InnoDB: Completed initialization of buffer pool2015-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 MB2015-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 MB2015-03-27 12:40:11 2861 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB2015-03-27 12:40:13 2861 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile02015-03-27 12:40:13 2861 [Warning] InnoDB: New log files created, LSN=457812015-03-27 12:40:13 2861 [Note] InnoDB: Doublewrite buffer not found: creating new2015-03-27 12:40:13 2861 [Note] InnoDB: Doublewrite buffer created2015-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 created2015-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 start2015-03-27 12:40:13 2861 [Note] InnoDB: 5.6.22 started; log sequence number 0A random root password has been set. You will find it in '/root/.mysql_secret'.2015-03-27 12:40:13 2861 [Note] Binlog end2015-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 16259772015-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 pages2015-03-27 12:40:15 2883 [Note] InnoDB: The InnoDB memory heap is disabled2015-03-27 12:40:15 2883 [Note] InnoDB: Mutexes and rw_locks use InnoDB's own implementation2015-03-27 12:40:15 2883 [Note] InnoDB: Memory barrier is not used2015-03-27 12:40:15 2883 [Note] InnoDB: Compressed tables use zlib 1.2.32015-03-27 12:40:15 2883 [Note] InnoDB: Using Linux native AIO2015-03-27 12:40:15 2883 [Note] InnoDB: Not using CPU crc32 instructions2015-03-27 12:40:15 2883 [Note] InnoDB: Initializing buffer pool, size = 128.0M2015-03-27 12:40:15 2883 [Note] InnoDB: Completed initialization of buffer pool2015-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 start2015-03-27 12:40:15 2883 [Note] InnoDB: 5.6.22 started; log sequence number 16259772015-03-27 12:40:15 2883 [Note] Binlog end2015-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 1625987A 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_installationwhich 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.comSupport MySQL by buying support/licenses at http://shop.mysql.comNew default config file was created as /usr/my.cnf andwill 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 mysqluid=101(mysql) gid=104(mysql) groups=104(mysql)开启mysql服务[root@fyl Mysql]# service mysql startStarting MySQL.[  OK  ][root@fyl Mysql]# ps -fu mysqlUID        PID  PPID  C STIME TTY          TIME CMDmysql     3090  3089  0 12:43 pts/2    00:00:00 -bashmysql     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默认端口3306tcp        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 -pEnter 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): 5w3BxVJOWqhz545xmysql> show databases;ERROR 1820 (HY000): You must SET PASSWORD before executing this statementmysql> 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 shutdownEnter 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/mysqlbasedir=datadir=/u01/mysql修改/usr/bin/mysqld_safe的datadir的目录值[root@fyl lib]#vi /usr/bin/mysqld_safe   注释掉之前的代码   #DATADIR=/var/lib/mysql   修改为:   DATADIR=/u01/mysql5、配置my.cnf文件该版本安装完没有/etc/my.cnf和/usr/share/mysql/my-medium.cnf直接   vi /etc/my.cnf[root@fyl etc]# cat my.cnf[client]#password       = your_passwordport            = 3306socket          = /u01/mysql/mysql.sockdefault-character-set=utf8[mysqld]port            = 3306socket          = /u01/mysql/mysql.sockskip-external-lockingkey_buffer_size = 16Mmax_allowed_packet = 1Mtable_open_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8Mcharacter_set_server=utf8collation-server=utf8_general_cilower_case_table_names=1character_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 = 20Msort_buffer_size = 20Mread_buffer = 2Mwrite_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.sock7、验证[root@fyl mysql]# service mysql startStarting MySQL.[  OK  ][root@fyl mysql]# service mysql stopShutting down MySQL..[  OK  ]







0 0
原创粉丝点击