12步安装MySQL-Server5.5.32

Linux软件的安装方式:

a. yum/rpm 特点:简单,快,无法定制。
b. 编译安装 ./configure; make; make install 特点:复杂,速度慢,可定制,针对mysql,是第一条产品线的编译方式
c. cmake安装 mysql 5.5以上的版本, ./cmake; gmake ;gmake install
d. 二进制包安装,直接解压就能使用(相当于绿色软件,无需安装)
今天主要安装的方式选择二进制包。
安装环境:Centos 6.5
软件包名:mysql-5.5.32-linux2.6-x86_64.tar.gz
下载链接:http://pan.baidu.com/s/1c12HUAs 密码:3yfz
1、创建mysql使用用户

[[email protected] tools]# useradd -s /sbin/nologin -M mysql

2、解压MySQL压缩包

[[email protected] tools]# tar -xvf mysql-5.5.32-linux2.6-x86_64.tar.gz
[[email protected] tools]# ls
mysql-5.5.32-linux2.6-x86_64         mysql-5.5.32-linux2.6-x86_64.tar.gz

3、mv移动走,因为是进制包,所以不需要安装,移动到application目录中
另需要创建软连接,使用ln -s,必须写全路径
操作到这此步,相当于make与make install

[[email protected] tools]# mv mysql-5.5.32-linux2.6-x86_64 /application/mysql-5.5.32-linux2.6-x86_64
[[email protected] application]# ln -s /application/mysql-5.5.32-linux2.6-x86_64/ /application/mysql
[[email protected] application]# ll
total 8
lrwxrwxrwx  1 root root   42 Jun 30 21:40 mysql -> /application/mysql-5.5.32-linux2.6-x86_64/
drwxr-xr-x 13 root root 4096 Jun 30 21:36 mysql-5.5.32-linux2.6-x86_64

4、查看初始化帮助文档,了解自己要加的编译参数

[[email protected] /]# /application/mysql/scripts/mysql_install_db --help
Usage: /application/mysql/scripts/mysql_install_db [OPTIONS]
  --basedir=path       The path to the MySQL installation directory.
  --builddir=path      If using --srcdir with out-of-directory builds, you
                       will need to set this to the location of the build
                       directory where built files reside.
  --cross-bootstrap    For internal use.  Used when building the MySQL system
                       tables on a different host than the target.
  --datadir=path       The path to the MySQL data directory.
  --defaults-extra-file=name
                       Read this file after the global files are read.
  --defaults-file=name Only read default options from the given file name.
  --force              Causes mysql_install_db to run even if DNS does not
                       work.  In that case, grant table entries that normally
                       use hostnames will use IP addresses.
  --help               Display this help and exit.                     
  --ldata=path         The path to the MySQL data directory. Same as --datadir.
  --no-defaults        Don‘t read default options from any option file.
  --rpm                For internal use.  This option is used by RPM files
                       during the MySQL installation process.
  --skip-name-resolve  Use IP addresses rather than hostnames when creating
                       grant table entries.  This option can be useful if
                       your DNS does not work.
  --srcdir=path        The path to the MySQL source directory.  This option
                       uses the compiled binaries and support files within the
                       source tree, useful for if you don‘t want to install
                       MySQL yet and just want to create the system tables.
  --user=user_name     The login username to use for running mysqld.  Files
                       and directories created by mysqld will be owned by this
                       user.  You must be root to use this option.  By default
                       mysqld runs using your current login name and files and
                       directories that it creates will be owned by you.

5、初始化数据库
/application/mysql/scripts/mysql_install_db:指定安装的命令
–basedir=指定mysql的安装目录
–datadir=data目录,存放mysql数据文件的位置
–user=指定使用的用户
以下执行的重要标识就是两个OK,如下出现两个OK,初步可以判断安装成功。
注意:如果这个位置出现错误,第一查看根下的/tmp是否是1777权限,第二尝试修改Mysql目录权限,第三修改hosts
一般都是因为/tmp写不进去数据造成的。
如下报的警告是hosts主机名的问题,可以忽略。

[[email protected] /]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql
WARNING: The host ‘Qinglin-Test1‘ could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
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:
/application/mysql//bin/mysqladmin -u root password ‘new-password‘                ==>设置密码命令
/application/mysql//bin/mysqladmin -u root -h Qinglin-Test1 password ‘new-password‘==>改密码命令
Alternatively you can run:
/application/mysql//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 /application/mysql/ ; /application/mysql//bin/mysqld_safe &     ==>启动mysql命令
You can test the MySQL daemon with mysql-test-run.pl
cd /application/mysql//mysql-test ; perl mysql-test-run.pl         ==>测试mysql命令
Please report any problems with the /application/mysql//scripts/mysqlbug script!

6、授权MySQL管理数据库文件

[[email protected] /]# chown -R mysql.mysql /application/mysql

7、生成MySQL配置文件

[[email protected] /]# cp /application/mysql/support-files/my-small.cnf /etc/my.cnf 
cp: overwrite `/etc/my.cnf‘? y

8、配置启动MySQL
因为mysqld_safe这个脚本默认使用的是/usr/local/mysql,所以启动脚本时会找这里,但是我们变换了路径,所以需要修改替换 /usr/local/ 为/application/mysql,这样脚本才生效。

[[email protected] /]# sed -i ‘s#/usr/local/mysql#/application/mysql#g‘ /application/mysql/bin/mysqld_safe

9、启动mysql服务

[[email protected] /]# /application/mysql/bin/mysqld_safe &    
[1] 18352
[[email protected] /]# 160630 22:18:40 mysqld_safe Logging to ‘/application/mysql/data/Qinglin-Test1.err‘.
160630 22:18:41 mysqld_safe Starting mysqld daemon with databases from /application/mysql/data

10、检查服务与端口

[[email protected] /]# ps -ef|grep mysql
root     18352 18175  0 22:18 pts/0    00:00:00 /bin/sh /application/mysql/bin/mysqld_safe
mysql    18570 18352  0 22:18 pts/0    00:00:00 /application/mysql/bin/mysqld --basedir=/application/mysql --datadir=/application/mysql/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/application/mysql/data/Qinglin-Test1.err --pid-file=/application/mysql/data/Qinglin-Test1.pid --socket=/tmp/mysql.sock --port=3306
root     18588 18175  0 22:19 pts/0    00:00:00 grep --color=auto mysql

11、配置环境变量

[[email protected] /]# vim /etc/profile
切换到最后一行,添加
PATH="/application/mysql/bin:$PATH"
[[email protected] /]# source /etc/profile

12、测试登录

[[email protected] /]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MySQL安装扩展知识

13、配置传统方式启动MySQL
思路:拷贝,然后添加执行权限,然后killall掉之前启动的mysql服务,最好再重复上面的检查一下,使用ps命令

[[email protected] /]# cp /application/mysql/support-files/mysql.server  /etc/init.d/mysqld
[[email protected] /]# chmod +x /etc/init.d/mysqld 
[[email protected] /]# killall mysqld

14、传统启动MySQL并加开机自启动选项。
注意:这里将拷贝到init.d的mysql脚本中的路径替换,和之前的问题一样,如果不替换的话找不到文件,并会报错。

[[email protected] /]# sed -i ‘s#/usr/local/mysql#/application/mysql#g‘  /etc/init.d/mysqld 
[[email protected] /]# /etc/init.d/mysqld start
Starting MySQL..                                           [  OK  ]
[[email protected] /]# chkconfig mysqld on
[[email protected] /]# chkconfig --list |grep mysql
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

15、设置MySQL的root密码和更改密码,并登陆

[email protected] /]# mysqladmin -uroot password "123456"
[[email protected] /]# mysqladmin -uroot -p‘123456‘ password ‘qinglin‘
[[email protected] /]# mysql -uroot -p‘qinglin‘
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.5.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql>

16、安全优化
删除默认的test数据库

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
mysql> drop database test; 
Query OK, 0 rows affected (0.01 sec)

删除无用用户(保留 root),不使用drop的原因是里成包含大写drop不识别,且不够快捷。

mysql> select user,host from mysql.user;     
+------+---------------+
| user | host          |
+------+---------------+
| root | 127.0.0.1     |
| root | ::1           |
|      | Qinglin-Test1 |
| root | Qinglin-Test1 |
|      | localhost     |
| root | localhost     |
+------+---------------+
6 rows in set (0.00 sec)
mysql> delete from mysql.user where user=‘‘;
Query OK, 0 rows affected (0.00 sec)
mysql> delete from mysql.user where host=‘Qinglin-Test1‘;
Query OK, 0 rows affected (0.00 sec)
mysql> delete from mysql.user where host=‘::1‘;
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from mysql.user;                 
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
+------+-----------+
2 rows in set (0.00 sec)

FAQ

问题1:
问题原因:初始化问题
解决方法:删除data目录重建,重新初始化

[[email protected] ~]# mysql
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)

问题2:
问题原因:权限问题
解决方法:chmod -R 1777 /tmp

ERROR: 1 Can‘t create/write to file

问题3:
问题原因:上传错误
解决方法:rz 不要打勾。ASCII
问题4:
问题原因:ERROR 20002错误
解决方法:服务没有启动

ERROR 2002(HY000): Can‘t connect to local MySQL server through socket  ...
时间: 2024-08-03 05:07:32

12步安装MySQL-Server5.5.32的相关文章

Ubuntu 12.04 安装MySQL

转自: http://www.cnblogs.com/yhLinux/p/4012689.html 本文是对 Ubuntu 12.04 环境下安装 MySQL 的记录,通过这两天的折腾,不断试错,才发现要完整地掌握 MySQL 安装其实并不复杂,关键是遇到问题时记住到官方文档寻找解决方案,在网络上搜索的网友的方法不一定适合你,而官方文档是比较全面的,建议大家有问题多看看. 安装MySQL的方法有多种方式,包括源码安装,包管理器安装,二进制安装等.之前,我使用最快的方式--包管理器安装,但安装完成

ubuntu 12.04lts 安装mysql ,并通过QT连接

安装server$ sudo apt-get install mysql-server 安装驱动 $ sudo apt-get install libqt4-sql-mysql $ dpkg --list | grep mysql ii libdbd-mysql-perl 4.020-1build2 Perl5 database interface to the MySQL database ii libmysqlclient18 5.5.47-0ubuntu0.12.04.1 MySQL da

CentOS7.2最小安装的虚拟机上安装MySQL 5.6.32

1.MySQL 5.6.32 64位安装包下载 在官网http://dev.mysql.com/downloads/mysql/5.6.html#中使用迅雷下载MySQL 5.6.32 64位安装包下载(或者wget 下载: # cd /usr/local/src # wget http://cdn.mysql.com/Downloads/MySQL-5.6/MySQL-5.6.32-1.linux_glibc2.5.x86_64.rpm-bundle.tar) (http://cdn.mysq

CentOS7.2虚拟机上安装MySQL 5.6.32

1.MySQL 5.6.32 64位安装包下载 在官网http://dev.mysql.com/downloads/mysql/5.6.html#中使用迅雷下载MySQL 5.6.32 64位安装包下载: (http://cdn.mysql.com//Downloads/MySQL-5.6/MySQL-5.6.32-1.linux_glibc2.5.x86_64.rpm-bundle.tar) 2.把下载文件通过SecureFX传递到/usr/local/src/目录中(虚拟主机CentOS7.

2-14 MySQL初步认识,及CentOS6.8环境,源码方式安装MySQL

什么是数据库: 存放数据的仓库RDBMS-->(Relational Database Management System) 关系型数据库管理系统DBMS--->(Database Managerment System) 数据库管理系统 数据库分类:1. 关系型数据库2. 非关系型数据库常用关系型数据库:Oracle,MySQL,MariaDB,SQL Server,Access,PostgreSQL,DB2,Informix,SybasePostgreSQL 自由的对象-关系数据库服务器(数

Linux下安装MySQL并为其创建新用户图解教程

Linux下安装MySQL并为其创建新用户图解教程 思路概述 1.下载所需的安装包 (Linux下用wget下载,笔者在window下下载的,用XSHELL命令RZ上传到Linux中) 2.安装MySQL 3.创建新用户并授权 图解教程 第一步: 检测系统版本信息 Linux命令:  cat /proc/version 当前Linux版本为RedHat 4.1.2-48 Linux命令: uname -a 可以看到当前系统为64位的 第二步:下载mysql Community Server 官方

【MySQL】源码编译安装和配置MySql 5.5.32(单实例)

[需求描述] 在CentOS环境中,通过编译源码的方式,安装并且配置“单实例”的MySQL5.5.32数据库. MySQL的安装目录为:/application/mysql-5.5.32 MySQL数据文件的安装目录为:/application/mysql-5.5.32/data MySQL默认的字符编码为:UTF8 [环境参数] VMware:10.0.1 Host:Win7 DB:MySql 5.5.32 编译工具:cmake-2.8.8.tar.gz 其他依赖:ncurses-devel-

centos 6.5 32位 编译安装Mysql

groupadd mysql #添加mysql组 useradd -g mysql mysql -s /bin/false #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统 mkdir -p /data/mysql #创建MySQL数据库存放目 chown -R mysql:mysql /data/mysql #设置MySQL数据库目录权限 mkdir -p /usr/local/mysql #创建MySQL安装目录 cd /opt tar zxvf mysql-5.5

redhat5.4 32位安装mysql 5.6.17数据库及创建数据库实例、配置编码、卸载

下载地址:http://pan.baidu.com/s/1eQ3o3Uq 一.安装 1.1.安装MySQL-server-5.6.17-1 1.[[email protected] mysql]# rpm -ivh MySQL-server-5.6.17-1.linux_glibc2.5.i386.rpm  Preparing... ########################################### [100%] 1:MySQL-server ################