tyrtyrt 发表于 2017-3-10 16:54:00

linux之MySQL安装部署

MySQL安装配置步骤:

1.    进入/home/oldboy/tools 执行上传mysql数据库指令并创建一个mysql用户
#rz -y上传压缩包
# cd /home/oldboy/tools/
# useradd -s /sbin/nologin-M mysql
# ls
mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz

2.    解压mysql安装包
# tar xf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
# 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
# mv mysql-5.6.35-linux-glibc2.5-x86_64 /application/mysql-5.6.35
# ls /application/
mysql-5.6.35

4.    给mysql创建一个软链接
# ln -s /application/mysql-5.6.35 /application/mysql
# ll /application/
total 8
lrwxrwxrwx1 root root   25 Mar8 23:41 mysql -> /application/mysql-5.6.35
drwxr-xr-x 13 root root 4096 Mar8 23:38 mysql-5.6.35


5.    赋予mysql安装目录中mysql软件的所属者
# chown -R mysql.mysql /application/mysql/
# ll mysql/
total 68
drwxr-xr-x2 mysql mysql4096 Mar8 23:38 bin
-rw-r--r--1 mysql mysql 17987 Nov 28 21:36 COPYING
drwxr-xr-x3 mysql mysql4096 Mar8 23:38 data
drwxr-xr-x2 mysql mysql4096 Mar8 23:38 docs
drwxr-xr-x3 mysql mysql4096 Mar8 23:38 include
drwxr-xr-x3 mysql mysql4096 Mar8 23:38 lib
drwxr-xr-x4 mysql mysql4096 Mar8 23:38 man
drwxr-xr-x 10 mysql mysql4096 Mar8 23:38 mysql-test
-rw-r--r--1 mysql mysql2496 Nov 28 21:36 README
drwxr-xr-x2 mysql mysql4096 Mar8 23:38 scripts
drwxr-xr-x 28 mysql mysql4096 Mar8 23:38 share
drwxr-xr-x4 mysql mysql4096 Mar8 23:38 sql-bench
drwxr-xr-x2 mysql mysql4096 Mar8 23:38 support-files

6.    初始化数据库
# /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 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系统服务并给执行权限
# cp /application/mysql/support-files/mysql.server/etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld

# ll /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10875 Mar8 23:51 /etc/init.d/mysqld


8.    替换配置文件
# sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld

9.    覆盖原来的配置文件

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

10.启动mysql服务
# /etc/init.d/mysqld start
Starting MySQL.Logging to '/application/mysql/data/localhost.err'.
SUCCESS!

# lsof -i:3306          #MySQL默认端口3306
COMMANDPIDUSER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld5189 mysql   10uIPv630071      0t0TCP *:mysql (LISTEN)

11.PATH路径和开机自启动
# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
# source /etc/profile
# which mysql
/application/mysql/bin/mysql
#    chkconfig --add mysqld

#    chkconfig mysqld on
# chkconfig --list|grep mysqld
mysqld             0:off    1:off    2:on    3:on    4:on    5:on    6:off

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

测试是否能登陆

# 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 wordpress@'172.16.1.%' identified by '123456'

sdylag 发表于 2017-3-12 21:11:08

{:6_394:}{:6_394:}{:6_394:}
感谢分享。
页: [1]
查看完整版本: linux之MySQL安装部署