MySQL基础部分
mysql安装脚本
安装前请将相关安装包copy放到/server/tools目录下
-rw-r--r-- 1 root root 314149697 Mar 23 2017 mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz
执行安装脚本:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #!/bin/bash 2 #install MySQL 3 #新增用户 4 useradd -M -s /sbin/nologin mysql 5 #进入软件目录 6 cd /server/tools 7 #解压 8 tar xf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz 9 #移动目录并创建软连接 10 mv mysql-5.6.34-linux-glibc2.5-x86_64 /application/mysql-5.6.34 11 ln -s /application/mysql-5.6.34/ /application/mysql 12 #授权 13 chown -R mysql.mysql /application/mysql/data/ 14 #初始化程序 15 /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data --user=mysql 16 #配置启动脚本进行授权 17 cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld 18 chmod +x /etc/init.d/mysqld 19 sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld 20 cp /application/mysql/support-files/my-default.cnf /etc/my.cnf 21 22 #优化:将命令增加到环境变量 23 echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile 24 source /etc/profile 25 26 #加入开机自启动 27 chkconfig --add mysqld 28 chkconfig mysqld on 29 #启动服务 30 /etc/init.d/mysqld start
安装完后执行ps-ef | grep mysql查看
[root@web01 tools]# ps -ef | grep mysql
root 10937 1 0 19:53 pts/2 00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --datadir=/application/mysql/data --pid-file=/application/mysql/data/web01.pid
mysql 11053 10937 0 19:53 pts/2 00:00:01 /application/mysql/bin/mysqld --basedir=/application/mysql --datadir=/application/mysql/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/application/mysql/data/web01.err --pid-file=/application/mysql/data/web01.pid
root 11162 10821 0 20:19 pts/2 00:00:00 grep mysql
给mysql用户设置密码
[root@web01 ~]# mysqladmin -u root password 'oldboy123' --设置root密码为oldboy123
Warning: Using a password on the command line interface can be insecure.
[root@web01 ~]# mysql -uroot -poldboy123 --登录root用户
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 6
Server version: 5.6.34 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