Linux下安装mysql

  首先,linux下有多种方法,①为编译的,②编译的tar.gz包,③,编译的rpm;本文打算叙述rpm形式的安装过程:后边将书tar.gz包的安装及一些问题的解决参考

一、下载安装包

官方网站下载,或者百度云链接下载:

MySQL-server-5.7.4_m14-1.el6.x86_64.rpm

MySQL-client-5.7.4_m14-1.el6.x86_64.rpm 

二、检查与清理原来是否有安装残留

  如果确信没有安装过mysql服务就不用了,如果是重装或者不确定可以逐级查看

  如果有用yum安装过使用命令: yum remove mysql* 卸载

  然后删除mysql旧有的文件和文件夹残留或者数据,:

    rm - rf mysql****

  杀死mysqld进程 kill -9 mysqld

  特别注意:/etc/my.cnf文件、/usr/bin、/usr/share下的mysql相关的文件也要一并删除,此外还有安装过程中的/etc/init.d/mysql配置文件的删除

三、安装rpm包及解决可能出现的依赖

  安装一中下载的rpm文件,先安装server.prm 文件,然后安装 client.rpm文件

  rpm -ivh 文件名.rpm

[root@localhost /]# rpm -ivh MySQL-server-5.7.4_m14-1.el6.x86_64.rpm

error: Failed dependencies:

net-tools is needed by MySQL-server-5.7.4_m14-1.el6.x86_64

学要解决net-tools依赖,可以参考:yum解决依赖关系,中的

YUM常见命令用法如下:

1.列出所有可更新的软件清单,命令:yum check-update   软件名称

2.安装所有更新软件,命令:yum update   软件名称

3.仅安装指定的软件,命令:yum install  软件名称

4.列出所有可安裝的软件清单,命令:yum list

5.用YUM安装删除软件,命令:yum remove   软件名称

    简单使用: yum install net-tools  然后y同意即可,但是后便会有点小问题 看见Complete!才算是安装 net-tools成功

    后边再执行 rpm -ivh xxx.rpm 后看见一堆冲突:

file /usr/share/mysql/charsets/README from install of MySQL-server-5.7.4_m14-1.el6.x86_64 conflicts with file from package mariadb-libs-1:5.5.47-1.el7_2.x86_64

……

file /usr/share/mysql/czech/errmsg.sys from install of MySQL-server-5.7.4_m14-1.el6.x86_64 conflicts with file from package mariadb-libs-1:5.5.47-1.el7_2.x86_64

很简单,就是之前的文件没有删除干净,重新检查,删除一下。

  之前我自己用有用yum安装过mariadb-libs-1:5.5.47-1.el7_2.x86_64,所以用上变得命令 yum remove mariadb-libs-1:5.5.47-1.el7_2.x86_64 删除这个包mariadb-libs-1:5.5.47-1.el7_2.x86_64

然后再执行 rpm -ivh XXX

Preparing... ################################# [100%]

find: '/var/lib/mysql': No such file or directory

Updating / installing...

1:MySQL-server-5.7.4_m14-1.el6 ################################# [100%]

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.

留意上边的修改密码提示。

然后安装client:

[root@localhost /]# rpm -ivh MySQL-client-5.7.4_m14-1.el6.x86_64.rpm

Preparing... ################################# [100%]

Updating / installing...

1:MySQL-client-5.7.4_m14-1.el6 ################################# [100%]


四、设置密码与简单使用

   查看服务是否启动,即3306端口是否在启动:netstat -nat

  启动服务:service mysql start

[root@localhost /]# service mysql start

Starting MySQL.. ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).

[root@localhost /]# service mysql restart

ERROR! MySQL server PID file could not be found!

Starting MySQL.. ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).

还是原来的问题,还是原来的提示,这酸爽!!!

进入提示的文件夹,果然没有那个pid文件,然后vim localhost.localdomain.err  查看问题没有什么有用的信息。

简直是,执行rpm -ql MySQL-server-5.7.4_m14-1.el6.x86_64.rpm 

  package MySQL-server-5.7.4_m14-1.el6.x86_64.rpm is not installed 显示的是未安装???

[root@localhost /]# service mysql start

Starting MySQL.. ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).

查资料说有僵尸进程:参考使用命令:ps -aux | grep mysqld  显示如下:

root 2591 0.0 0.3 8984 808 pts/0 S+ 03:44 0:00 grep --color=auto mysqld

然后执行 ps -aux 的会看到个字段的意思。

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

杀掉进程:kill -9 进程号

但是还是启动不了:第二种没用

终极tie 我想笑:丢失了pid怎么办最终自己新建了一个 /var/lib/mysql/localhost.localdomain.pid文件,里边直接写入 ps -aux | grep mysqld 读到的pid值,保存就行。

   [root@localhost mysql]# service mysql start

Starting MySQL SUCCESS!

然而:netstat -nat 还是查询不到33006端口,再次启动还是是失败。

登录:

五、卸载

------------

   tar.gz形式的安装。

一、下载安装包

二、创建mysql用户

三、安装数据库

[root@localhost sever]# cd mysql-5.7.11

[root@localhost mysql-5.7.11]# cd bin

[root@localhost bin]# ./mysql_install_db --user=mysql --basedir=/home/mysql/ --datadir=/home/mysql/data

2016-04-04 22:09:05 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize

2016-04-04 22:09:06 [ERROR] Child process: /usr/sever/mysql-5.7.11/bin/mysqldterminated prematurely with errno= 32

2016-04-04 22:09:06 [ERROR] Failed to execute /usr/sever/mysql-5.7.11/bin/mysqld --bootstrap --datadir=/home/mysql/data --lc-messages-dir=/usr/share/mysql --lc-messages=en_US --basedir=/home/mysql

-- server log begin --

2016-04-05T02:09:05.358823Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead

2016-04-05T02:09:05.359564Z 0 [Warning] Changed limits: max_open_files: 4096 (requested 5000)

2016-04-05T02:09:05.359573Z 0 [Warning] Changed limits: table_open_cache: 1967 (requested 2000)

2016-04-05T02:09:05.360209Z 0 [ERROR] Can't read from messagefile '/usr/share/mysql/english/errmsg.sys'

-- server log end --

[root@localhost bin]# ./mysqld --user=mysql --basedir=/home/mysql/ --datadir=/home/mysql/data

2016-04-05T02:10:35.847170Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2016-04-05T02:10:35.847260Z 0 [Warning] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.

2016-04-05T02:10:35.847293Z 0 [Note] ./mysqld (mysqld 5.7.11) starting as process 16732 ...

2016-04-05T02:10:35.847327Z 0 [ERROR] Can't find error-message file '/home/mysql/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.

2016-04-05T02:10:35.850131Z 0 [ERROR]

2016-04-05T02:10:35.850147Z 0 [ERROR] Couldn't load plugin named 'keyring_file' with soname 'keyring_file.so'.

2016-04-05T02:10:35.850690Z 0 [Note] InnoDB: PUNCH HOLE support not available

2016-04-05T02:10:35.850832Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

2016-04-05T02:10:35.850842Z 0 [Note] InnoDB: Uses event mutexes

2016-04-05T02:10:35.850848Z 0 [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier

2016-04-05T02:10:35.850852Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3

2016-04-05T02:10:35.850858Z 0 [Note] InnoDB: Using Linux native AIO

2016-04-05T02:10:35.851146Z 0 [Note] InnoDB: Number of pools: 1

2016-04-05T02:10:35.851259Z 0 [Note] InnoDB: Using CPU crc32 instructions

2016-04-05T02:10:35.860704Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M

2016-04-05T02:10:35.871080Z 0 [Note] InnoDB: Completed initialization of buffer pool

2016-04-05T02:10:35.873518Z 0 [ERROR] [FATAL] InnoDB: pthread_create returned 11

2016-04-04 22:10:35 0x7f7a8aa26740 InnoDB: Assertion failure in thread 140164288636736 in file ut0ut.cc line 920

InnoDB: We intentionally generate a memory trap.

InnoDB: Submit a detailed bug report to http://bugs.mysql.com.

InnoDB: If you get repeated assertion failures or crashes, even

InnoDB: immediately after the mysqld startup, there may be

InnoDB: corruption in the InnoDB tablespace. Please refer to

InnoDB: http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html

InnoDB: about forcing recovery.

02:10:35 UTC - mysqld got signal 6 ;

This could be because you hit a bug. It is also possible that this binary

or one of the libraries it was linked against is corrupt, improperly built,

or misconfigured. This error can also be caused by malfunctioning hardware.

Attempting to collect some information that could help diagnose the problem.

As this is a crash and something is definitely wrong, the information

collection process might fail.

key_buffer_size=8388608

read_buffer_size=131072

max_used_connections=0

max_threads=151

thread_count=0

connection_count=0

It is possible that mysqld could use up to

key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 68188 K bytes of memory

Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0x0

Attempting backtrace. You can use the following information to find out

where mysqld died. If you see no messages after this, something went

terribly wrong...

stack_bottom = 0 thread_stack 0x40000

./mysqld(my_print_stacktrace+0x35)[0xf45595]

./mysqld(handle_fatal_signal+0x4a4)[0x77fd34]

/lib64/libpthread.so.0(+0xf130)[0x7f7a8a606130]

/lib64/libc.so.6(gsignal+0x37)[0x7f7a892075d7]

/lib64/libc.so.6(abort+0x148)[0x7f7a89208cc8]

./mysqld[0x10dd465]

./mysqld(_ZN2ib5fatalD1Ev+0xb3)[0x10e2b33]

./mysqld(_Z21os_thread_create_funcPFPvS_ES_Pm+0x277)[0xff3d37]

./mysqld(_Z34innobase_start_or_create_for_mysqlv+0x1686)[0x1097196]

./mysqld[0xf7669d]

./mysqld(_Z24ha_initialize_handlertonP13st_plugin_int+0x51)[0x7caac1]

./mysqld[0xd35576]

./mysqld(_Z11plugin_initPiPPci+0x965)[0xd3a3c5]

./mysqld[0x77641b]

./mysqld(_Z11mysqld_mainiPPc+0x516)[0x779316]

/lib64/libc.so.6(__libc_start_main+0xf5)[0x7f7a891f3af5]

./mysqld[0x76fdc9]

The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains

information that should help you find out what is causing the crash.



四、配置文件

[root@localhost mysql-5.7.11]# cd support-files/

[root@localhost support-files]# cp my-default.cnf /etc/my.cnf

cp: overwrite '/etc/my.cnf'? yes

[root@localhost support-files]# cp mysql.server /etc/init.d/mysql

[root@localhost support-files]# vim /etc/init.d/mysql

#!/bin/sh

#!/bin/sh

# Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB

# This file is public domain and comes with NO WARRANTY of any kind

# MySQL daemon start/stop script.

# Usually this is put in /etc/init.d (at least on machines SYSV R4 based

# systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.

# When this is done the mysql server will be started when the machine is

# started and shut down when the systems goes down.

# Comments to support chkconfig on RedHat Linux

# chkconfig: 2345 64 36

# description: A very fast and reliable SQL database engine.

# Comments to support LSB init script conventions

### BEGIN INIT INFO

# Provides: mysql

# Required-Start: $local_fs $network $remote_fs

# Should-Start: ypbind nscd ldap ntpd xntpd

# Required-Stop: $local_fs $network $remote_fs

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

# Short-Description: start and stop MySQL

# Description: MySQL is a very fast and reliable SQL database engine.

### END INIT INFO

# If you install MySQL on some other places than /usr/local/mysql, then you

# have to do one of the following things for this script to work:

#

# - Run this script from within the MySQL installation directory

# - Create a /etc/my.cnf file with the following information:

# [mysqld]

# basedir=<path-to-mysql-installation-directory>

# - Add the above to any other configuration file (for example ~/.my.ini)

# and copy my_print_defaults to /usr/bin

# - Add the path to the mysql-installation-directory to the basedir variable

# below.

#

# If you want to affect other MySQL variables, you should make your changes

# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.

# If you change base dir, you must also change datadir. These may get

# overwritten by settings in the MySQL configuration files.

basedir=/home/mysql/

datadir=/home/mysql/data

# Default value, in seconds, afterwhich the script should timeout waiting

# for server start.

# Value here is overriden by value in my.cnf.

# 0 means don't wait at all

# Negative numbers mean to wait indefinitely

service_startup_timeout=900

# Lock directory for RedHat / SuSE.

lockdir='/var/lock/subsys'

lock_file_path="$lockdir/mysql"

# The following variables are only set for letting mysql.server find things.

五、配置环境变量

vi .bash_profile

# User specific environment and startup programs

export MYSQL_HOME="/home/mysql/mysql-5.7.9"

export PATH="$PATH:$MYSQL_HOME/bin" 

六、添加开机启动服务

chkconfig --add mysql

chkconfig mysql on

七、启动mysql

[root@localhost ~]# su - mysql

[mysql@localhost ~]$ service mysql start

Starting MySQL ERROR! Couldn't find MySQL server (/home/mysql//bin/mysqld_safe)

(果然出错了)~~~~~

basedir=/usr/sever/mysql-5.7.11/

datadir=/home/mysql/data

然后修改到末尾出现:

E45: 'readonly' option is set (add ! to override)

按照网上的解决方案:ESC后输入:wq!,(参考链接)

强制保存后,显示的错误

"/etc/rc.d/init.d/mysql"

"/etc/rc.d/init.d/mysql" E212: Can't open file for writing

Enter后,继续ESC :x显示

E505: "/etc/rc.d/init.d/mysql" is read-only (add ! to override)  

(如果仍旧不能保存退出的话,就重启开启以个连接修改试试,可能会出现 --bash-4.2问题),上变得不能够编辑的问题可能是由于我在[mysql@localhost ~]路径下修改文件原因。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,236评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,867评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,715评论 0 340
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,899评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,895评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,733评论 1 283
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,085评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,722评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,025评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,696评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,816评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,447评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,057评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,009评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,254评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,204评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,561评论 2 343

推荐阅读更多精彩内容

  • // 查询出来已安装的mariadb [root@localhost ~]# rpm -qa|grep maria...
    橡皮泥阅读 248评论 0 0
  • Mysql数据库的安装对于开发者来说,是我们必然会面对的问题,它的安装过程其实并不复杂,并且网上的安装教程也非常多...
    alone_f0fd阅读 315评论 1 1
  • 今天突然想:在云上安装mysql玩玩。记录下操作步骤:其中:/usr/local/mysql 是安装目录/data...
    一一一二二三阅读 3,807评论 0 0
  • 可以使用yum命令安装mysql,或者直接用安装包解压安装。yum的方式网上有很多,基本上都是一步到位,本文主要写...
    酸奶泡奥利奥阅读 336评论 0 0
  • 官方下载地址 : https://dev.mysql.com/downloads/mysql/ 操作系统我们选择l...
    yandaren阅读 239评论 0 0