Linux下面安装MySQL详细步骤讲解

今天下午在Linux下装了MySQL,我的是虚拟机里面装的CentOs7版本,装mysql的过程中遇到了一些问题,网上的回答又是乱七八糟,为了使朋友们少走弯路,特把我今天安装的全部流程总结如下:

1,首先我是先从官网下下载一个"mysql-5.7.20 .tar.gz"这个版本的来用,安装的过程中遇到很多问题,比如执行"mysql_install_db --user=mysql "会报错,提升找不到这个路径下的mysql_install_db这个问题,我到此路径下看了看,发现的确没有这个文件,上网搜了搜说是什么源码版本安装,没有编译之类云云,总之没有一个人能给出详细解决方案,最后果断弃之不用,换成另外一种安装方式,也就是rpm方式安装,比较条条大路通罗马嘛


2,在网上下载"MySQL-5.6.25-1.linux_glibc2.5.x86_64.rpm-bundle .tar"这个版本的MySQL,里面一共有7个文件,实际上安装的时候只适用两个,一个是服务器端"MySQL-server-5.6.25-1.linux_glibc2.5.x86_64.rpm",一个是客户端"MySQL-client-5.6.25-1.linux_glibc2.5.x86_64.rpm",通过英文名字大家应该都清楚.


3,通过"SecureFX 7.3"或者"Xshell 5"工具把第二步当中的7个文件拷贝到Linux的root目录下面,你也可以在根目录下专门建立一个文件夹来存放这些文件(比如/geming/),


4,然后cd到此文件夹所在目录,执行以下命令"[root@localhost geming]# rpm -ivh MySQL-server-5.6.25-1.linux_glibc2.5.x86_64.rpm ",这是安装服务器端.


然后会抛出如下信息:


Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]
2017-10-18 22:04:02 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-10-18 22:04:02 0 [Note] /usr/sbin/mysqld (mysqld 5.6.25) starting as process 5166 ...
2017-10-18 22:04:02 5166 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-10-18 22:04:02 5166 [Note] InnoDB: The InnoDB memory heap is disabled
2017-10-18 22:04:02 5166 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-10-18 22:04:02 5166 [Note] InnoDB: Memory barrier is not used
2017-10-18 22:04:02 5166 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-10-18 22:04:02 5166 [Note] InnoDB: Using Linux native AIO
2017-10-18 22:04:02 5166 [Note] InnoDB: Using CPU crc32 instructions
2017-10-18 22:04:02 5166 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-10-18 22:04:03 5166 [Note] InnoDB: Completed initialization of buffer pool
2017-10-18 22:04:03 5166 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2017-10-18 22:04:03 5166 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2017-10-18 22:04:03 5166 [Note] InnoDB: Database physically writes the file full: wait...
2017-10-18 22:04:03 5166 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2017-10-18 22:04:03 5166 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2017-10-18 22:04:04 5166 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2017-10-18 22:04:04 5166 [Warning] InnoDB: New log files created, LSN=45781
2017-10-18 22:04:04 5166 [Note] InnoDB: Doublewrite buffer not found: creating new
2017-10-18 22:04:04 5166 [Note] InnoDB: Doublewrite buffer created
2017-10-18 22:04:04 5166 [Note] InnoDB: 128 rollback segment(s) are active.
2017-10-18 22:04:04 5166 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-10-18 22:04:04 5166 [Note] InnoDB: Foreign key constraint system tables created
2017-10-18 22:04:04 5166 [Note] InnoDB: Creating tablespace and datafile system tables.
2017-10-18 22:04:04 5166 [Note] InnoDB: Tablespace and datafile system tables created.
2017-10-18 22:04:04 5166 [Note] InnoDB: Waiting for purge to start
2017-10-18 22:04:04 5166 [Note] InnoDB: 5.6.25 started; log sequence number 0
A random root password has been set. You will find it in '/root/.mysql_secret'.
2017-10-18 22:04:07 5166 [Note] Binlog end
2017-10-18 22:04:07 5166 [Note] InnoDB: FTS optimize thread exiting.
2017-10-18 22:04:07 5166 [Note] InnoDB: Starting shutdown...
2017-10-18 22:04:09 5166 [Note] InnoDB: Shutdown completed; log sequence number 1625977




2017-10-18 22:04:10 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-10-18 22:04:10 0 [Note] /usr/sbin/mysqld (mysqld 5.6.25) starting as process 5188 ...
2017-10-18 22:04:10 5188 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-10-18 22:04:10 5188 [Note] InnoDB: The InnoDB memory heap is disabled
2017-10-18 22:04:10 5188 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-10-18 22:04:10 5188 [Note] InnoDB: Memory barrier is not used
2017-10-18 22:04:10 5188 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-10-18 22:04:10 5188 [Note] InnoDB: Using Linux native AIO
2017-10-18 22:04:10 5188 [Note] InnoDB: Using CPU crc32 instructions
2017-10-18 22:04:10 5188 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-10-18 22:04:10 5188 [Note] InnoDB: Completed initialization of buffer pool
2017-10-18 22:04:10 5188 [Note] InnoDB: Highest supported file format is Barracuda.
2017-10-18 22:04:10 5188 [Note] InnoDB: 128 rollback segment(s) are active.
2017-10-18 22:04:10 5188 [Note] InnoDB: Waiting for purge to start
2017-10-18 22:04:10 5188 [Note] InnoDB: 5.6.25 started; log sequence number 1625977
2017-10-18 22:04:11 5188 [Note] Binlog end
2017-10-18 22:04:11 5188 [Note] InnoDB: FTS optimize thread exiting.
2017-10-18 22:04:11 5188 [Note] InnoDB: Starting shutdown...
2017-10-18 22:04:12 5188 [Note] InnoDB: Shutdown completed; log sequence number 1625987








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.


Also, the account for the anonymous user has been removed.


In addition, you can run:


  /usr/bin/mysql_secure_installation


which 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.com


Support MySQL by buying support/licenses at http://shop.mysql.com


New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings


此即为安装服务器端成功


5,[root@localhost geming]# netstat -nat,,,,这一步是查看你的端口是否可用,里面会显示一些端口信息..

    tcp        0      0 0.0.0.0:22                 0.0.0.0:*                   LISTEN   比如这是端口在监听状态

  等等一些信息


6,接下来启动mysql服务器,执行以下命令"[root@localhost geming]# service mysql start"

    提示如下信息:Starting MySQL...................... SUCCESS! 


7,接下来开始安装mysql客户端了,执行如下命令"[root@localhost geming]# rpm -ivh MySQL-client-5.6.25-1.linux_glibc2.5.x86_64.rpm  "

    执行后有如下信息:

     Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]

   这表明已经安装成功


8,接下来执行"[root@localhost geming]# cp /usr/share/mysql/my-default.cnf  /etc/my.cnf",,,这个的作用是将配置文件复制到my.cnf里面,,大家进入/usr/share/mysql/my-default.cnf这个路径下面应该有这个文件,因为mysql安装成功后会自动出现my-default.cnf和my.cnf这两个文件,路径也是上面的路径,应该是自动生成的.


9,执行以下命令"[root@localhost geming]# vim /etc/my.cnf",进入vim模式下编辑

   vim操作想必大家都很熟悉吧,不熟悉的同志,我在这里多啰嗦两句

   首先,执行以上命令进入vim之后,按键盘上的"i"键进入编辑模式,上下左右键可以控制位置,编辑完成后,按键盘左上角的"Esc"键,然后按"shift+:",输入wq,自动就保存并且退出.

    进入vim编辑模式后会出现如下信息,大家按照我写的来做就可以了,向下看:

   

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.


蓝色字体的同志们需要自己手动赋值添加过去,当然了,也可以根据需要自己配置

[client]
port=3306
socket=/var/lib/mysql/mysql.sock

[mysqld]
character_set_server = utf8
port = 3306
datadir = /usr/share/mysql/mysqldata
socket =/var/lib/mysql/mysql.sock
explicit_defaults_for_timestamp=true
skip_name_resolve
log_bin_trust_function_creators = 1
event_scheduler=ON


lower_case_table_names=1
federated

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M


# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
max_connections = 1000
max_connect_errors = 10000



# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
server_id =0
# socket = .....

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysql]
default-character-set = utf8

  

10,安装的过程结束后会随机生成一个密码:执行如下命令可以查看到这个密码

    [root@localhost geming]# cat /root/.mysql_secret 
    # The random password set for the root user at Wed Oct 18 22:04:05 2017 (local time):dBD5aaeMxsuc64gf

     把这个密码保存到桌面,接下来你就可以以root用户名和这个密码配合起来登录了


11,最后提示一下,第一次登录进去的时候,你需要修改默认密码,但是问题就在于这个修改密码这里,,,,当执行如下命令的时候会报错

     mysql> use mysql
    ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
    mysql>

    就是说你想进入到mysql这里,然后使用update这个命令修改密码的时候是行不通的,因为你是第一次登录.

    所以,最后,我迫不得已,执行"Ctrl+c"退出MySQL,然后进入到Linux模式下执行下面的命令:

   [root@localhost geming]# mysqladmin -u root -p password "123geming"
   Enter password: 
   Warning: Using a password on the command line interface can be insecure.

   最后一句英文的意思上,在外面执行不太安全,在mysql里面修改密码更安全,但是,我在mysql模式修改了,但是不成功,所以这英文等于脱了裤子放屁多此一举.

    最后你就可以使用你新修改的密码来登录了.

    如果不足,请大家多多留言,


    补充一下,如果说要MySQL的安装文件,可以给我留言,我通过qq发给你们.

   


猜你喜欢

转载自blog.csdn.net/geming2017/article/details/78279293