MYSQL安装Linux二进制安装

可了解的网站

https://www.cnblogs.com/lyq863987322/p/8074025.html

http://blog.51cto.com/xujun1270/1932818  最全的网站了

https://www.cnblogs.com/pyrene/p/6517586.html

https://www.cnblogs.com/pyrene/p/6517586.html相同的操作了

 

mysql root dl20180829

 

二进制安装mysql

特点,安装快,不好定制,解压可直接使用

id mysql

useradd -s /sbin/nologin -M mysql

id mysql

tar -xvf mysql.xx-linux.xx.tar.gz  (相当于编译安装make install)

mv mysql.版本 /application/mysql.版本    移动

ln -s /application/mysql.版本 /application/mysql  (去版本号)

ls -l /application

 

chown -R mysql.mysql /application/mysql-5.7.17 (安装目录,授权给mysql)

rm -fr /application/mysql/scripts/mysql/data/*   (把data 下的初始话数据删掉)

初始化配置数据库

/application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql

--basedir=/application/mysql-5.7.17  指定安装目录

--datadir=/application/mysql-5.7.17/data  指定存放数据文件的地方

--user=mysql  指定用户

两个ok 完成

 

执行初始化的输出信息:最后一行有初始密码,一定要先记住

Installing MySQL system tables...2018-11-21 23:57:58 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2018-11-21 23:57:58 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.

2018-11-21 23:57:58 0 [Note] /application/mysql//bin/mysqld (mysqld 5.6.42) starting as process 3893 ...

2018-11-21 23:57:58 3893 [Note] InnoDB: Using atomics to ref count buffer pool pages

2018-11-21 23:57:58 3893 [Note] InnoDB: The InnoDB memory heap is disabled

2018-11-21 23:57:58 3893 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

2018-11-21 23:57:58 3893 [Note] InnoDB: Memory barrier is not used

2018-11-21 23:57:58 3893 [Note] InnoDB: Compressed tables use zlib 1.2.11

2018-11-21 23:57:58 3893 [Note] InnoDB: Using Linux native AIO

2018-11-21 23:57:58 3893 [Note] InnoDB: Using CPU crc32 instructions

2018-11-21 23:57:58 3893 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2018-11-21 23:57:58 3893 [Note] InnoDB: Completed initialization of buffer pool

2018-11-21 23:57:58 3893 [Note] InnoDB: Highest supported file format is Barracuda.

2018-11-21 23:57:58 3893 [Note] InnoDB: 128 rollback segment(s) are active.

2018-11-21 23:57:58 3893 [Note] InnoDB: Waiting for purge to start

2018-11-21 23:57:58 3893 [Note] InnoDB: 5.6.42 started; log sequence number 1600627

2018-11-21 23:57:59 3893 [Note] Binlog end

2018-11-21 23:57:59 3893 [Note] InnoDB: FTS optimize thread exiting.

2018-11-21 23:57:59 3893 [Note] InnoDB: Starting shutdown...

2018-11-21 23:58:00 3893 [Note] InnoDB: Shutdown completed; log sequence number 1626007

OK

Filling help tables...2018-11-21 23:58:00 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2018-11-21 23:58:00 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.

2018-11-21 23:58:00 0 [Note] /application/mysql//bin/mysqld (mysqld 5.6.42) starting as process 3916 ...

2018-11-21 23:58:00 3916 [Note] InnoDB: Using atomics to ref count buffer pool pages

2018-11-21 23:58:00 3916 [Note] InnoDB: The InnoDB memory heap is disabled

2018-11-21 23:58:00 3916 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

2018-11-21 23:58:00 3916 [Note] InnoDB: Memory barrier is not used

2018-11-21 23:58:00 3916 [Note] InnoDB: Compressed tables use zlib 1.2.11

2018-11-21 23:58:00 3916 [Note] InnoDB: Using Linux native AIO

2018-11-21 23:58:00 3916 [Note] InnoDB: Using CPU crc32 instructions

2018-11-21 23:58:00 3916 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2018-11-21 23:58:00 3916 [Note] InnoDB: Completed initialization of buffer pool

2018-11-21 23:58:00 3916 [Note] InnoDB: Highest supported file format is Barracuda.

2018-11-21 23:58:00 3916 [Note] InnoDB: 128 rollback segment(s) are active.

2018-11-21 23:58:00 3916 [Note] InnoDB: Waiting for purge to start

2018-11-21 23:58:00 3916 [Note] InnoDB: 5.6.42 started; log sequence number 1626007

2018-11-21 23:58:00 3916 [Note] Binlog end

2018-11-21 23:58:00 3916 [Note] InnoDB: FTS optimize thread exiting.

2018-11-21 23:58:00 3916 [Note] InnoDB: Starting shutdown...

2018-11-21 23:58:02 3916 [Note] InnoDB: Shutdown completed; log sequence number 1626017

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 iZwz988rg4xz5qa9f7ldrbZ 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//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 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 /application/mysql//my.cnf and

will be used by default by the server when you start it.

You may edit this file to change server settings

WARNING: Default config file /etc/my.cnf exists on the system

This file will be read by default by the MySQL server

If you do not want to use this, either remove it, or use the

--defaults-file argument to mysqld_safe when starting the server

 

生成MySQL配置文件

都是在 support/下的.cnf 文件(需要去找生产环境的配置)

cp /application/mysql-5.7.17/support-files/my-default.cnf /etc/my.cnf

修改启动文件内容

因为启动文件中指定的mysql程序路径与安装路径不同,所以需要改过来
sed -i "s#/usr/local/mysql/#/application/mysql/#g" /application/mysql/bin/mysqld_safe这句报错

 

sed -i 's#/usr/local/mysql#/application/mysql-1.14.1#g' /application/mysql-1.14.1/bin/mysqld_safe
 
sed -i 's#/usr/local/mysql#/application/mysql-1.14.1#g' /application/mysql-1.14.1/bin/mysqld_safe
sed-i's#/usr/local/mysql#/application/mysql#g' /application/mysql-1.14.1/bin/mysqld_safe
sed-i's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe
sed-i's#/usr/local#/mysql#/application/mysql#' /application/mysql-1.14.1/bin/mysqld_safe
sed -i 's#/usr/local#/mysql#/application/mysql#' /application/mysql-1.14.1/bin/mysqld_safe
好像
/application/mysql/bin/mysqld_safe &  启动mysql  (& 在后台启动)
配置环境变量
Vi /etc/profile
PATH=”/application/mysql/bin:$PATH”
Source /etc/profile
或者使用
cp /application//mysql-1.14.1/bin/* /usr/local/sbin/
查看是否sbin下    如果use/bin 下是系统的yum安装

 

 

 

登陆mysql
 
科学启动方法
cp /application/mysql-5.7.17/support-files/mysql.server /etc/init.d/mysqld
mysql 的启动脚本
替换路径
sed -i 's#/usr/local/mysql#/application/mysql#g' /etc/init.d/mysqld
增加执行权限 chmod +X /etc/init.d/mysqld

杀掉当前数据库 killall mysqld

平滑杀掉mysql /etc/init.d/mysqld stop

平滑开启mysql /etc/init.d/mysqld start

chkconfig mysqld on

chkconfig --list mysqld  (设置成开机自启动)

sqld          0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭

Lsof -I :3306

netstat -lntup

 

Mysql 安全优化

设置密码:mysqladmin -uroot password ‘mima’ #linux

修改密码:mysqladmin -uroot -pmima password “nemima”

删除test库:drop database test;

删除无用用户:drop user ‘用户’@主机

查询用户:select user,host from mysql.user;

grant all on *.* to ‘root’@localhost identified by ‘123456’with grant ortino;flush privileges    #创建maysql用户命令

 

 

 

Delete from mysql.user where user=”root” and host=”A”

 

flush privileges; #刷新让权限生效 

 

 

 

MYSQL 集群搭建

上传

创建用户 useradd -s /sbin/nologin -M mysql

id mysql

解压 tar -xvf 包

Mkdir  /appli

 

报错情况 

 

由于tem_db  权限错误,需要改回原权限 chamod -R 1777 /tmp

 

 

 

初始化数据库

/application/mysql-1.14.1/scripts/mysql_install_db --basedir=/application/mysql-1.14.1/ --datadir=/application/mysql-1.14.1/data/ --user=mysql

Installing MySQL system tables...2018-11-22 10:32:31 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2018-11-22 10:32:31 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.

2018-11-22 10:32:31 0 [Note] /application/mysql-1.14.1//bin/mysqld (mysqld 5.6.42) starting as process 5318 ...

2018-11-22 10:32:31 5318 [Note] InnoDB: Using atomics to ref count buffer pool pages

2018-11-22 10:32:31 5318 [Note] InnoDB: The InnoDB memory heap is disabled

2018-11-22 10:32:31 5318 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

2018-11-22 10:32:31 5318 [Note] InnoDB: Memory barrier is not used

2018-11-22 10:32:31 5318 [Note] InnoDB: Compressed tables use zlib 1.2.11

2018-11-22 10:32:31 5318 [Note] InnoDB: Using Linux native AIO

2018-11-22 10:32:31 5318 [Note] InnoDB: Using CPU crc32 instructions

2018-11-22 10:32:31 5318 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2018-11-22 10:32:31 5318 [Note] InnoDB: Completed initialization of buffer pool

2018-11-22 10:32:31 5318 [Note] InnoDB: Highest supported file format is Barracuda.

2018-11-22 10:32:31 5318 [Note] InnoDB: 128 rollback segment(s) are active.

2018-11-22 10:32:31 5318 [Note] InnoDB: Waiting for purge to start

2018-11-22 10:32:31 5318 [Note] InnoDB: 5.6.42 started; log sequence number 1600607

2018-11-22 10:32:32 5318 [Note] Binlog end

2018-11-22 10:32:32 5318 [Note] InnoDB: FTS optimize thread exiting.

2018-11-22 10:32:32 5318 [Note] InnoDB: Starting shutdown...

2018-11-22 10:32:33 5318 [Note] InnoDB: Shutdown completed; log sequence number 1625987

OK

 

Filling help tables...2018-11-22 10:32:33 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2018-11-22 10:32:33 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.

2018-11-22 10:32:33 0 [Note] /application/mysql-1.14.1//bin/mysqld (mysqld 5.6.42) starting as process 5341 ...

2018-11-22 10:32:33 5341 [Note] InnoDB: Using atomics to ref count buffer pool pages

2018-11-22 10:32:33 5341 [Note] InnoDB: The InnoDB memory heap is disabled

2018-11-22 10:32:33 5341 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

2018-11-22 10:32:33 5341 [Note] InnoDB: Memory barrier is not used

2018-11-22 10:32:33 5341 [Note] InnoDB: Compressed tables use zlib 1.2.11

2018-11-22 10:32:33 5341 [Note] InnoDB: Using Linux native AIO

2018-11-22 10:32:33 5341 [Note] InnoDB: Using CPU crc32 instructions

2018-11-22 10:32:33 5341 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2018-11-22 10:32:33 5341 [Note] InnoDB: Completed initialization of buffer pool

2018-11-22 10:32:33 5341 [Note] InnoDB: Highest supported file format is Barracuda.

2018-11-22 10:32:33 5341 [Note] InnoDB: 128 rollback segment(s) are active.

2018-11-22 10:32:33 5341 [Note] InnoDB: Waiting for purge to start

2018-11-22 10:32:33 5341 [Note] InnoDB: 5.6.42 started; log sequence number 1625987

2018-11-22 10:32:33 5341 [Note] Binlog end

2018-11-22 10:32:33 5341 [Note] InnoDB: FTS optimize thread exiting.

2018-11-22 10:32:33 5341 [Note] InnoDB: Starting shutdown...

2018-11-22 10:32:35 5341 [Note] InnoDB: Shutdown completed; log sequence number 1625997

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-1.14.1//bin/mysqladmin -u root password 'new-password'

  /application/mysql-1.14.1//bin/mysqladmin -u root -h iZwz988rg4xz5qa9f7ldrbZ password 'new-password'

Alternatively you can run:

  /application/mysql-1.14.1//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-1.14.1//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 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

WARNING: Found existing config file /application/mysql-1.14.1//my.cnf on the system.

Because this file might be in use, it was not replaced,

but was used in bootstrap (unless you used --defaults-file)

and when you later start the server.

The new default config file was created as /application/mysql-1.14.1//my-new.cnf,

please compare it with your file and take the changes you need.

WARNING: Default config file /etc/my.cnf exists on the system

This file will be read by default by the MySQL server

If you do not want to use this, either remove it, or use the

--defaults-file argument to mysqld_safe when starting the server

 

posted @ 2019-10-26 21:24  Xingtxx  阅读(2)  评论(0编辑  收藏  举报