二进制安装mysql教程

目录

1、拷贝安装包
2、增加用户组及用户
3、解压安装包
4、创建软链接
5、修改用户权限
6、安装MySQL
7、拷贝启动脚本
8、修改环境变量
9、拷贝模板文件
10、修改/etc/my.cnf
11、启动MySQL服务


1、拷贝安装包

将获取到的MySQL安装包上传到服务器指定目录下。

步骤

  1. 在服务器上创建/opt/mysql目录。
mkdir /opt/mysql
  1. 以二进制方式FTP上传mysql-5.5.35-linux2.6-x86_64.tar.gz到服务器的/opt/mysql目录下。
    增加用户组及用户
    增加安装用户以及用户所属组。
    如果已经存在mysql用户,删除后重新添加。
    步骤
  2. (可选)执行如下命令,删除mysql用户。
userdel -r mysql
  1. (可选)执行如下命令,删除mysql用户组。
 groupdel mysql
  1. 执行如下命令,增加mysql用户组。
groupadd mysql
  1. 执行如下命令,增加mysql用户。
useradd mysql -d /opt/mysql/mysql -g mysql

解压安装包
将MySQL安装包解压缩,为安装做好准备。

步骤

  1. 执行如下命令,解压安装包。
tar -zxvf mysql-5.5.35-linux2.6-x86_64.tar.gz
  1. 执行如下命令,查看解压后的目录,确定解决成功。
ll
total 17999
drwxr-xr-x 13 root root 4096 Jul 2 11:46 mysql-5.5.35-linux2.6-x86_64
-rw-r--r-- 1 root root 184122460 Jul 2 11:45 mysql-5.5.35-linux2.6-x86_64.tar.gz

创建软链接

步骤

  1. 执行如下命令,创建链接。
ln -s mysql-5.5.35-linux2.6-x86_64 mysql
  1. 执行如下命令,查看创建的链接,确定创建成功。
 ll

lrwxrwxrwx 1 root root 28 Jul 2 11:47 mysql -> mysql-5.5.35-linux2.6-x86_64
drwxr-xr-x 13 root root 4096 Jul 2 11:46 mysql-5.5.35-linux2.6-x86_64
-rw-r--r-- 1 root root 184122460 Jul 2 11:45 mysql-5.5.35-linux2.6-x86_64.tar.gz

修改用户权限
赋予安装包mysql用户权限。
步骤

  1. 执行如下命令,赋予安装包权限。
chown -R mysql:root mysql-5.5.35-linux2.6-x86_64 mysql
  1. 执行如下命令,查看目录权限,确定赋权成功。
ll
lrwxrwxrwx 1 mysql root 28 Jul 2 11:47 mysql -> mysql-5.5.35-linux2.6-x86_64
drwxr-xr-x 13 mysql root 4096 Jul 2 11:46 mysql-5.5.35-linux2.6-x86_64
-rw-r--r-- 1 root root 184122460 Jul 2 11:45 mysql-5.5.35-linux2.6-x86_64.tar.gz 

安装MySQL
执行安装命令,开始安装MySQL。
步骤

  1. 执行命令# su - mysql,切换用户。
# su - mysql
  1. 执行如下命令,进入MySQL目录。
$ cd /opt/mysql/mysq
  1. 执行如下命令,安装MySQL。
$ ./scripts/mysql_install_db
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h dap153-169 password 'new-password'
Alternatively you can run:
./bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl
Please report any problems with the ./bin/mysqlbug script!
  1. 执行完毕,执行如下命令,退出mysql用户。
$ exit
logout

拷贝启动脚本
拷贝脚本到指定目录,并赋予脚本可执行权限。

步骤

  1. 执行如下命令,切换到/etc/rc.d /init.d目录下。
# cd /etc/init.d
  1. 执行如下命令,拷贝myslq.server的启动脚本程序到该目录。
#cp /opt/mysql/mysql/support-files/mysql.server mysql
  1. 执行如下命令,赋予脚本可执行权限。
#chmod +x mysql
  1. 执行如下命令,查看脚本权限。
# ll|grep mysql
-rwxr-xr-x 1 root root 10880 Jul 2 11:52 mysql

修改环境变量
修改环境变量并使修改后的环境变量生效。

步骤

  1. 执行如下命令,相关启动路径写入环境变量(/etc/profile)。
# echo 'PATH=$PATH:/opt/mysql/mysql/bin' >> /etc/profile
  1. 执行如下命令,是环境变量并生效。
# source /etc/profile

拷贝模板文件

步骤

  1. 拷贝模板文件到/etc路径下,并重命名。
# cp /opt/mysql/mysql/support-files/my-medium.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? yes #如果原来/etc目录下有my.cnf文件,则覆盖。

修改/etc/my.cnf

步骤

  1. 执行如下命令,编辑配置文件/etc/my.cnf。
# vi /etc/my.cnf
  1. 根据需要,修改配置文件/etc/my.cnf。
# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, do:
# 'my_print_defaults --help' and see what is printed under
# Default options are read from the following files in the given order:
# More information at: http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
basedir= /opt/mysql/mysql #设定工作目录
datadir= /opt/mysql/mysql/data #设定数据目录
expire_logs_days = 3 #增加日志老化机制,本文范例保留3天内的日志信息
event_scheduler=ON #启动数据库定时清理机制
port = 3306
socket = /tmp/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
myisam_sort_buffer_size = 8M
character_set_server=utf8 #设定字符集
max_connections=200 #设定最大连接数
lower_case_table_names = 1 #设定数据库名和表名大小写不敏感
max_connect_errors = 100000 #设定连接错误为一个较大值
innodb_file_format = barracuda #接着的3个配置项目解决主键不能超过767 bytes的限制
innodb_file_per_table = true
innodb_large_prefix = true
# Point the following paths to different dedicated disks
#tmpdir = /tmp/ 
 
启动MySQL服务
步骤
1.  执行如下命令,启动MySQL服务。

/etc/init.d/mysql restart

Shutting down MySQL. done
Starting MySQL.. done

或者使用命令:service mysql start启动MySQL服务。 

你可能感兴趣的:(二进制安装mysql教程)