1.1 Mysql安装

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1.1 Mysql安装相关的知识,希望对你有一定的参考价值。

mysql是数据库文件(存储数据);

1.下载(猿课论坛链接或者官网)合适版本(官网5.7,我们学习用5.1);免编译的二进制包。源码包就需要编译器编译成能够支持的二进制文件。注意下载的时候和系统位数(32/64位)的区分
[[email protected] ~]# cd/usr/local/src/

[[email protected] src] wgethttp://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz

[[email protected] src]# ls

[[email protected] src]# du -shmysql-5.1.73-linux-x86_64-glibc23.tar.gz

2.解压 tar

[[email protected] src]# tar zxvf mysql-5.1.73-linux-x86_64-glibc23.tar.gz

[[email protected] src]# ls

mysql-5.1.73-linux-x86_64-glibc23  mysql-5.1.73-linux-x86_64-glibc23.tar.gz

3、建立mysql用户

创建运行mysql的账户不需要登陆  可不创建家目录

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

[[email protected] src]# ls /home 验证

aming jishan  mysql  user1 user2  user4  user9

4.移动并重命名。把解压完的数据移动到/usr/local/mysql

 

[[email protected] src]# mv mysql-5.1.73-linux-x86_64-glibc23   /usr/local/mysql 移动带重命名 之前这个目录不存在/usr/local/mysq

查看mysql文件

[[email protected] src]# ls /usr/local/mysql 验证    /usr/local/mysql等于mysql-5.1.73-linux-x86_64-glibc23  

bin     data  include         lib mysql-test  scripts  sql-bench

COPYING docs  INSTALL-BINARY  man README      share    support-files

5.初始化数据库

进入   cd  /usr/local/mysql 

[[email protected] src]# cd /usr/local/mysql 

创建存放mysql数据的文件夹并更改权限 

[[email protected] mysql]# mkdir -p /data/mysql

[[email protected] mysql]# chown -R mysql /data/mysql

[[email protected] mysql]#  ./scripts/mysql_install_db --user=mysql  --datadir=/data/mysql 初始化完成就有两个“ok”。也可以用命令 echo$? 检测,如果输出为0 表示成功。

Installing MySQL system tables...

OK

Filling help tables...

OK

备注:如果是版本mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz编译会报错,#因为我的linux是最小化安装的,这里报错缺少共享库文件,没关系,我们安装一下就可以了。 yum install -y libaio

[[email protected] mysql]# ./scripts/mysql_install_db--user=mysql  --datadir=/dat                                  a/mysql

Installing MySQL system tables..../bin/mysqld: errorwhile loading shared librar                                  ies:libaio.so.1: cannot open shared object file: No such file or directory

[[email protected] mysql]# ./scripts/mysql_install_db--user=mysql  --datadir=/data/mysql

Installing MySQL system tables..../bin/mysqld: errorwhile loading shared libraries: libaio.so.1: cannot open shared object file: Nosuch file or directory

[[email protected] mysql]#  yum install -y libaio   5.5版本安装这个yum install -y libaio*  

 

 

6.拷贝配置文件放在相应的目录里面。

[[email protected] mysql]# cd support-files/ 将配置文件放在相应的目录里面。配置文件存放目录

[[email protected] support-files]# ls

binary-configure   my-huge.cnf            mysqld_multi.server

config.huge.ini    my-innodb-heavy-4G.cnf  mysql-log-rotate

config.medium.ini  my-large.cnf           mysql.server

config.small.ini   my-medium.cnf          ndb-config-2-node.ini

magic              my-small.cnf

[[email protected] support-files]# cp my-large.cnf /etc/my.cnf  先将my-large.cnf拷贝到etc/my.cnf下并覆盖之前的配置文件

cp:是否覆盖"/etc/my.cnf" y

备注:如果是版本mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz需要执行cpmy-default.cnf /etc/my.cnf

 [[email protected] support-files]# ls

binary-configure magic  my-default.cnf mysqld_multi.server mysql-log-rotate  mysql.server

[[email protected] support-files]# cp my-large.cnf /etc/my.cnf

cp: 无法获取"my-large.cnf"的文件状态(stat): 没有那个文件或目录

-bash: syntax error near unexpected token `(‘

[[email protected] support-files]# cp my-default.cnf/etc/my.cnf

cp:是否覆盖"/etc/my.cnf" y

 

[[email protected] support-files]# vim my-large.cnf

[mysqld]

port            = 3306

socket          = /tmp/mysql.sock

skip-locking

key_buffer_size = 256M

max_allowed_packet = 1M

table_open_cache = 256

sort_buffer_size = 1M

read_buffer_size = 1M

read_rnd_buffer_size = 4M

myisam_sort_buffer_size = 64M

thread_cache_size = 8

query_cache_size= 16M

# Try number of CPU‘s*2 forthread_concurrency

thread_concurrency = 8

 

# Don‘t listen on a TCP/IP port at all.This can be a security enhancement,

# if all processes that need to connect tomysqld run on the same host.

# All interaction with mysqld must be madevia Unix sockets or named pipes.

# Note that using this option withoutenabling named pipes on Windows

# (via the "enable-named-pipe"option) will render mysqld useless!

#

#skip-networking

 

# Replication Master Server (default)

# binary logging is required forreplication

#log-bin=mysql-bin主从的时候用到 前面输入#注释

 

# binary logging format - mixed recommended

#binlog_format=mixed

 

# required unique id between 1 and 2^32 - 1

# defaults to 1 if master-host is not set

# but will not function as a master ifomitted

#server-id       = 1

7.拷贝启动脚本。加入到系统服务列表中并启动服务。

[[email protected] support-files]# cp mysql.server /etc/init.d/mysqld

[[email protected] mysql]# chmod 755 /etc/init.d/mysqld电子书上的说明,视频上介绍无

 

8、修改启动脚本

[[email protected] support-files]# vim /etc/init.d/mysqld

basedir=/usr/local/mysql

datadir=/data/mysql

9、把启动脚本加入系统服务项,并设定开机启动,启动mysql

[[email protected] support-files]# chkconfig --add mysqld    加入服务列表

[[email protected] support-files]# chkconfig mysqld on

 

[[email protected] support-files]# /etc/init.d/mysqld startservice mysqld start

Starting MySQL.. SUCCESS!

 [[email protected] support-files]# netstat -lnp |grep mysql 验证成功

技术分享

tcp       0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      3418/mysqld

unix 2      [ ACC ]     STREAM    LISTENING     29567  3418/mysqld         /tmp/mysql.sock

[[email protected] support-files]#

技术分享

5.6安装可以参考这个

http://blog.csdn.net/noob_f/article/details/51399335

5.7实战安装mysql-5.7.12可以参考这个

http://ask.apelearn.com/question/13004

 


以上是关于1.1 Mysql安装的主要内容,如果未能解决你的问题,请参考以下文章

web代码片段

从mysql的片段中加载ListView

连接MySQL出现错误:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)(代码片段

1.1 Mysql安装

mysql与hive2.1.1安装和配置

使用 json rereiver php mysql 在片段中填充列表视图