历史旧文
数据库随想
数据库安全
mysql 5.5.58 create user创建用户小例
innodb存储引擎
1,下载并上传mysql 5.5 tar.gz 2进制源码安装介质
[root@mygirl ~]# rz
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
100% 193930 KB 16160 KB/s 00:00:12 0 Errors.gz...
2, 解压上述源码文件
[root@mygirl ~]# pwd
/root
[root@mygirl ~]# ll mysql-5.5.58-linux-glibc2.12-x86_64.tar.gz
-rwxrwxrwx. 1 root root 198585153 Sep 13 23:33 mysql-5.5.58-linux-glibc2.12-x86_64.tar.gz
[root@mygirl local]# cd usr/local
[root@mygirl local]# pwd
/usr/local
[root@mygirl local]# tar zxvf root/mysql-5.5.58-linux-glibc2.12-x86_64.tar.gz
中间略
mysql-5.5.58-linux-glibc2.12-x86_64/man/man1/mysqlimport.1
mysql-5.5.58-linux-glibc2.12-x86_64/man/man1/mysql_waitpid.1
mysql-5.5.58-linux-glibc2.12-x86_64/man/man1/mysql_client_test_embedded.1
mysql-5.5.58-linux-glibc2.12-x86_64/man/man1/mysqldump.1
mysql-5.5.58-linux-glibc2.12-x86_64/man/man1/mysql_plugin.1
mysql-5.5.58-linux-glibc2.12-x86_64/man/man1/mysql_find_rows.1
[root@mygirl local]# ll
total 44
drwxr-xr-x. 2 root root 4096 May 4 2017 bin
drwxr-xr-x. 2 root root 4096 Jun 28 2011 etc
drwxr-xr-x. 2 root root 4096 Jun 28 2011 games
drwxr-xr-x. 3 root root 4096 Jul 2 03:05 include
drwxr-xr-x. 2 root root 4096 Jul 2 03:06 lib
drwxr-xr-x. 2 root root 4096 Jun 28 2011 lib64
drwxr-xr-x. 2 root root 4096 Jun 28 2011 libexec
drwxr-xr-x. 13 root root 4096 Dec 21 23:37 mysql-5.5.58-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 4096 Jun 28 2011 sbin
drwxr-xr-x. 6 root root 4096 Jul 2 03:05 share
drwxr-xr-x. 2 root root 4096 Jun 28 2011 src
[root@mygirl local]# ll mysql-5.5.58-linux-glibc2.12-x86_64/
total 72
drwxr-xr-x. 2 root root 4096 Dec 21 23:37 bin
-rw-r--r--. 1 7161 31415 17987 Sep 13 23:20 COPYING
drwxr-xr-x. 3 root root 4096 Dec 21 23:37 data
drwxr-xr-x. 2 root root 4096 Dec 21 23:37 docs
drwxr-xr-x. 3 root root 4096 Dec 21 23:37 include
-rw-r--r--. 1 7161 31415 301 Sep 13 23:20 INSTALL-BINARY
drwxr-xr-x. 3 root root 4096 Dec 21 23:37 lib
drwxr-xr-x. 4 root root 4096 Dec 21 23:37 man
drwxr-xr-x. 10 root root 4096 Dec 21 23:37 mysql-test
-rw-r--r--. 1 7161 31415 2496 Sep 13 23:20 README
drwxr-xr-x. 2 root root 4096 Dec 21 23:37 scripts
drwxr-xr-x. 27 root root 4096 Dec 21 23:37 share
drwxr-xr-x. 4 root root 4096 Dec 21 23:37 sql-bench
drwxr-xr-x. 2 root root 4096 Dec 21 23:37 support-files
3,创建部署mysql服务器软件的操作系统组及用户(注:分别为mysql和mysql)
[root@mygirl local]# groupadd mysql
[root@mygirl local]# useradd -r -g mysql -s bin/false mysql
[root@mygirl local]#
usr/local
[root@mygirl local]# ll
total 44
drwxr-xr-x. 2 root root 4096 May 4 2017 bin
drwxr-xr-x. 2 root root 4096 Jun 28 2011 etc
drwxr-xr-x. 2 root root 4096 Jun 28 2011 games
drwxr-xr-x. 3 root root 4096 Jul 2 03:05 include
drwxr-xr-x. 2 root root 4096 Jul 2 03:06 lib
drwxr-xr-x. 2 root root 4096 Jun 28 2011 lib64
drwxr-xr-x. 2 root root 4096 Jun 28 2011 libexec
drwxr-xr-x. 13 root root 4096 Dec 21 23:37 mysql-5.5.58-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 4096 Jun 28 2011 sbin
drwxr-xr-x. 6 root root 4096 Jul 2 03:05 share
drwxr-xr-x. 2 root root 4096 Jun 28 2011 src
4,切换至/usr/local,以软链接方式重命名解压mysql对应目录为mysql(当然你也可以不这样作,不这样作,就是操作比较别扭)
[root@mygirl local]# ln -s mysql-5.5.58-linux-glibc2.12-x86_64 mysql
[root@mygirl local]#
[root@mygirl local]# cd mysql
[root@mygirl mysql]# ll
total 72
drwxr-xr-x. 2 root root 4096 Dec 21 23:37 bin
-rw-r--r--. 1 7161 31415 17987 Sep 13 23:20 COPYING
drwxr-xr-x. 3 root root 4096 Dec 21 23:37 data
drwxr-xr-x. 2 root root 4096 Dec 21 23:37 docs
drwxr-xr-x. 3 root root 4096 Dec 21 23:37 include
-rw-r--r--. 1 7161 31415 301 Sep 13 23:20 INSTALL-BINARY
drwxr-xr-x. 3 root root 4096 Dec 21 23:37 lib
drwxr-xr-x. 4 root root 4096 Dec 21 23:37 man
drwxr-xr-x. 10 root root 4096 Dec 21 23:37 mysql-test
-rw-r--r--. 1 7161 31415 2496 Sep 13 23:20 README
drwxr-xr-x. 2 root root 4096 Dec 21 23:37 scripts
drwxr-xr-x. 27 root root 4096 Dec 21 23:37 share
drwxr-xr-x. 4 root root 4096 Dec 21 23:37 sql-bench
drwxr-xr-x. 2 root root 4096 Dec 21 23:37 support-files
[root@mygirl mysql]#
5,切换至/usr/local/mysql,授予权限为mysql:mysql
[root@mygirl mysql]# chown -Rf mysql:mysql .
[root@mygirl mysql]# ll
total 72
drwxr-xr-x. 2 mysql mysql 4096 Dec 21 23:37 bin
-rw-r--r--. 1 mysql mysql 17987 Sep 13 23:20 COPYING
drwxr-xr-x. 3 mysql mysql 4096 Dec 21 23:37 data
drwxr-xr-x. 2 mysql mysql 4096 Dec 21 23:37 docs
drwxr-xr-x. 3 mysql mysql 4096 Dec 21 23:37 include
-rw-r--r--. 1 mysql mysql 301 Sep 13 23:20 INSTALL-BINARY
drwxr-xr-x. 3 mysql mysql 4096 Dec 21 23:37 lib
drwxr-xr-x. 4 mysql mysql 4096 Dec 21 23:37 man
drwxr-xr-x. 10 mysql mysql 4096 Dec 21 23:37 mysql-test
-rw-r--r--. 1 mysql mysql 2496 Sep 13 23:20 README
drwxr-xr-x. 2 mysql mysql 4096 Dec 21 23:37 scripts
drwxr-xr-x. 27 mysql mysql 4096 Dec 21 23:37 share
drwxr-xr-x. 4 mysql mysql 4096 Dec 21 23:37 sql-bench
drwxr-xr-x. 2 mysql mysql 4096 Dec 21 23:37 support-files
6,继续切换至scripts子目录,初始化mysql系统数据库(注:这里面是一些管理mysql数据库的系统数据字典)
[root@mygirl mysql]# cd scripts/
[root@mygirl scripts]#
[root@mygirl scripts]# ll
total 16
-rwxr-xr-x. 1 mysql mysql 14764 Sep 14 01:29 mysql_install_db
[root@mygirl scripts]#
[root@mygirl scripts]# pwd
/usr/local/mysql/scripts
[root@mygirl scripts]# ./mysql_install_db --user=mysql
FATAL ERROR: Could not find ./bin/my_print_defaults
If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.
[root@mygirl scripts]#
综上可知,必须附加选项--basedir and --datadir(注:2个参数含义各为安装mysql软件的安装目录以及存储mysql数据文件的安装目录)
[root@mygirl scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
Installing MySQL system tables...
171221 23:51:11 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
171221 23:51:11 [Note] usr/local/mysql/bin/mysqld (mysqld 5.5.58) starting as process 3509 ...
OK
Filling help tables...
171221 23:51:11 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
171221 23:51:11 [Note] usr/local/mysql/bin/mysqld (mysqld 5.5.58) starting as process 3516 ...
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:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h mygirl password 'new-password'
Alternatively you can run:
/usr/local/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 /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
[root@mygirl scripts]#
7,启动mysql服务器进程(注:必须切换至/usr/local/mysql/bin,否则报错如下)
[root@mygirl mysql]# cd bin
[root@mygirl bin]# ./mysqld_safe &
[1] 3568
[root@mygirl bin]# Logging to '/usr/local/mysql/data/mygirl.err'.
171221 23:55:22 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[root@mygirl ~]# ps -ef|grep mysql
root 3568 2254 0 23:55 pts/0 00:00:00 /bin/sh ./mysqld_safe
mysql 3627 3568 0 23:55 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mygirl.err --pid-file=mygirl.pid
root 3674 3644 0 23:55 pts/1 00:00:00 grep mysql
[root@mygirl bin]# cd /usr/local/mysql/bin
[root@mygirl bin]# pwd
/usr/local/mysql/bin
[root@mygirl mysql]# pwd
/usr/local/mysql
8,登陆mysql服务器
[root@mygirl ~]# /usr/local/mysql/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.58 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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>
9,配置mysql服务器root用户密码(注:默认是无密码,不安全)
-------
mysql> select host,user,password from mysql.user where user='root';
+-----------+------+----------+
| host | user | password |
+-----------+------+----------+
| localhost | root | |
| mygirl | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
+-----------+------+----------+
4 rows in set (0.00 sec)
mysql> update mysql.user set password=password('zxy') where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
[root@mygirl ~]# /usr/local/mysql/bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.5.58 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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>
10,可以配置path环境变量,便于直接调用mysql各种命令
[root@mygirl ~]# export PATH=$PATH:/usr/local/mysql/bin
[root@mygirl ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@mygirl ~]# /usr/local/mysql/bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.5.58 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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>




