linux之MySQL安装部署

Posted

tags:

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

mysql安装配置步骤:


1.    进入/home/oldboy/tools 执行上传mysql数据库指令并创建一个mysql用户

#rz -y上传压缩包

[[email protected] tools]# cd /home/oldboy/tools/

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

[[email protected] tools]# ls

mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz


2.    解压mysql安装包

[[email protected] tools]# tar xf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz

[[email protected] tools]# ls

mysql-5.6.35-linux-glibc2.5-x86_64        mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz


3.    移动解压出来的mysql目录到指定目录

#没有这个目录则创建       mkdir -p /application

[[email protected] tools]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /application/mysql-5.6.35

[[email protected] tools]# ls /application/

mysql-5.6.35


4.    给mysql创建一个软链接

[[email protected] tools]# ln -s /application/mysql-5.6.35 /application/mysql

[[email protected] tools]# ll /application/

total 8

lrwxrwxrwx  1 root root   25 Mar  8 23:41 mysql -> /application/mysql-5.6.35

drwxr-xr-x 13 root root 4096 Mar  8 23:38 mysql-5.6.35

5.    赋予mysql安装目录中mysql软件的所属者
[[email protected] application]# chown -R mysql.mysql /application/mysql/

[[email protected] application]# ll mysql/

total 68

drwxr-xr-x  2 mysql mysql  4096 Mar  8 23:38 bin

-rw-r--r--  1 mysql mysql 17987 Nov 28 21:36 COPYING

drwxr-xr-x  3 mysql mysql  4096 Mar  8 23:38 data

drwxr-xr-x  2 mysql mysql  4096 Mar  8 23:38 docs

drwxr-xr-x  3 mysql mysql  4096 Mar  8 23:38 include

drwxr-xr-x  3 mysql mysql  4096 Mar  8 23:38 lib

drwxr-xr-x  4 mysql mysql  4096 Mar  8 23:38 man

drwxr-xr-x 10 mysql mysql  4096 Mar  8 23:38 mysql-test

-rw-r--r--  1 mysql mysql  2496 Nov 28 21:36 README

drwxr-xr-x  2 mysql mysql  4096 Mar  8 23:38 scripts

drwxr-xr-x 28 mysql mysql  4096 Mar  8 23:38 share

drwxr-xr-x  4 mysql mysql  4096 Mar  8 23:38 sql-bench

drwxr-xr-x  2 mysql mysql  4096 Mar  8 23:38 support-files


6.    初始化数据库
[[email protected] application]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data --user=mysql

Installing MySQL system tables...2017-03-08 23:50:31 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
…………
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

7.    复制mysql安装目录下的脚本去linux系统服务并给执行权限
[[email protected] application]# cp /application/mysql/support-files/mysql.server  /etc/init.d/mysqld

[[email protected] application]# chmod +x /etc/init.d/mysqld

[[email protected] application]# ll /etc/init.d/mysqld

-rwxr-xr-x 1 root root 10875 Mar  8 23:51 /etc/init.d/mysqld


8.    替换配置文件

[[email protected] application]# sed -i ‘s#/usr/local/mysql#/application/mysql#g‘ /application/mysql/bin/mysqld_safe /etc/init.d/mysqld

9.    覆盖原来的配置文件

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

10.  启动mysql服务

[[email protected] application]# /etc/init.d/mysqld start

Starting MySQL.Logging to ‘/application/mysql/data/localhost.err‘.
 SUCCESS!

[[email protected] application]# lsof -i:3306          #MySQL默认端口3306
COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld  5189 mysql   10u  IPv6  30071      0t0  TCP *:mysql (LISTEN)

11.  PATH路径和开机自启动

[[email protected] application]# echo ‘export PATH=/application/mysql/bin:$PATH‘ >>/etc/profile

[[email protected] application]# source /etc/profile

[[email protected] application]# which mysql

/application/mysql/bin/mysql

[[email protected] application]#    chkconfig --add mysqld

[[email protected] application]#    chkconfig mysqld on

[[email protected] application]# chkconfig --list|grep mysqld
mysqld             0:off    1:off    2:on    3:on    4:on    5:on    6:off

12.  给MySQL root用户设置密码
[[email protected] application]# /application/mysql/bin/mysqladmin -u root password ‘oldboy123‘
Warning: Using a password on the command line interface can be insecure.         #这个只是一个警告,原因是在命令行输入密码!


测试是否能登陆

[[email protected] application]# mysql -uroot -poldboy123

Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> quit
Bye

到这一步mysql数据库就安装成功了!MySQL常用命令如下   ↓




MySQL简单常用命令

1.    查看所有数据库:show databases;

2.    创建一个数据库:create database oldboy;

3.    删除一个数据库(危险):drop database oldboy;

4.    select user,host from mysql.user;

      查询选择:select

      user,host字段(列)

      mysql数据库的user表格

5.   退出MySQL:quit

6.   给用户授权:grant all on wordpress.* to [email protected]‘172.16.1.%‘ identified by ‘123456‘

本文出自 “lming” 博客,请务必保留此出处http://lmin32.blog.51cto.com/12206256/1904593

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

LAMP的部署安装

云原生之使用Docker部署Mysql数据库

linux安装部署mysql

Linux安装部署LAMP(Apache+MySQL+PHP)

MySQL之galera集群部署

部署LAMP架构之Mysql安装