mysql linux 安装部署,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
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
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‘
總結
以上是生活随笔為你收集整理的mysql linux 安装部署,linux之MySQL安装部署(示例代码)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux磁盘同步函数,Linux系统调
- 下一篇: pymysql语法_如何使用PyMySQ