[root@bogon ~]# ll
total 180548
-rw-------. 1 root root 990 Jul 22 14:39 anaconda-ks.cfg
drwxr-xr-x 2 root root 4096 Jul 29 13:29 Desktop
drwxr-xr-x 2 root root 4096 Jul 29 13:29 Documents
drwxr-xr-x 2 root root 4096 Jul 29 13:29 Downloads
-rw-r--r--. 1 root root 17369 Jul 22 14:39 install.log
-rw-r--r--. 1 root root 5820 Jul 22 14:37 install.log.syslog
drwxr-xr-x 2 root root 4096 Jul 29 13:29 Music
-rw-r--r-- 1 root root 184804825 Aug 18 2016 mysql-5.5.42-linux2.6-x86_64.tar.gz
drwxr-xr-x 2 root root 4096 Jul 29 13:29 Pictures
drwxr-xr-x 2 root root 4096 Jul 29 13:29 Public
drwxr-xr-x 4 root root 4096 Aug 17 14:40 rpmbuild
drwxr-xr-x 2 root root 4096 Jul 29 13:29 Templates
drwxr-xr-x 2 root root 4096 Jul 29 13:29 Videos
[root@bogon ~]#tar xf mysql-5.5.42-linux2.6-x86_64.tar.gz -C /usr/local/
[root@bogon ~]# cd /usr/local/
[root@bogon local]# ln -sv mysql-5.5.42-linux2.6-x86_64 mysql
[root@bogon local]#less /usr/mysql/INSTALL-BINARY #此命令是查看安装mysql的说明,说明中有安装mysql命令的使用。可参考翻阅;
.....
.....
To install and use a MySQL binary distribution, the basic
command sequence looks like this:
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
# Next command is optional
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
.....
.....
[root@bogon local]# cd mysql
[root@bogon mysql]# chown -R mysql:mysql ./* #这里一定要先更改属主属组,因为安装mysql说明中的步骤就是这么说的;
[root@bogon mysql]# scripts/mysql_install_db --help #执行初始化前,可先查看帮助信息;
Usage: scripts/mysql_install_db [OPTIONS]
--basedir=path The path to the MySQL installation directory.
--builddir=path If using --srcdir with out-of-directory builds, you
will need to set this to the location of the build
directory where built files reside.
--cross-bootstrap For internal use. Used when building the MySQL system
tables on a different host than the target.
--datadir=path The path to the MySQL data directory.
--defaults-extra-file=name
Read this file after the global files are read.
--defaults-file=name Only read default options from the given file name.
--force Causes mysql_install_db to run even if DNS does not
work. In that case, grant table entries that
normally use hostnames will use IP addresses.
--help Display this help and exit.
--ldata=path The path to the MySQL data directory. Same as --datadir.
--no-defaults Don't read default options from any option file.
--rpm For internal use. This option is used by RPM files
during the MySQL installation process.
--skip-name-resolve Use IP addresses rather than hostnames when creating
grant table entries. This option can be useful if
your DNS does not work.
--srcdir=path The path to the MySQL source directory. This option
uses the compiled binaries and support files within the
source tree, useful for if you don't want to install
MySQL yet and just want to create the system tables.
--user=user_name The login username to use for running mysqld. Files
and directories created by mysqld will be owned by this
user. You must be root to use this option. By default
mysqld runs using your current login name and files and
directories that it creates will be owned by you.
All other options are passed to the mysqld program
#在实际生产环境中,很有可能数据的增长会非常大,所以我们最好放在逻辑卷中,而且,为了防止数据的丢失和硬盘的损坏,它的底层最好是raid;
#这里我在虚拟机里新添加了一块硬盘,分区sdb1为lvm的id。这里不再添加代码。
[root@bogon mysql]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
[root@bogon mysql]# vgcreate mydata /dev/sdb1
Volume group "mydata" successfully created
[root@bogon mysql]# lvcreate -L 6G -n mysqldata mydata
Logical volume "mysqldata" created
[root@bogon mysql]# mke2fs -t ext4 /dev/mydata/mysqldata
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
393216 inodes, 1572864 blocks
78643 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1610612736
48 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@bogon mysql]# vim /etc/fstab
[root@bogon mysql]# mkdir /data
[root@bogon mysql]# mount -a
[root@bogon mysql]# mount
/dev/sda3 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/sda2 on /usr type ext4 (rw)
/dev/sda5 on /var type ext4 (rw)
/dev/sr0 on /media/cdrom type iso9660 (ro)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/mydata-mysqldata on /data type ext4 (rw,noatime)
[root@bogon mysql]# vim /etc/fstab #开机自动挂载
...
...
#添加如下代码
/dev/mydata/mysqldata /data ext4 defaults,noatime 0 0
...
...
[root@bogon mysql]# mkdir /data/mydata
[root@bogon mysql]# chown -R mysql.mysql /data/mydata/
[root@bogon mysql]# scripts/mysql_install_db --datadir=/data/mydata --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
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:
./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h bogon password 'new-password'
Alternatively you can run:
./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 . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
[root@bogon mysql]# chown -R root ./*
[root@bogon mysql]# ll
total 216
drwxr-xr-x 2 root mysql 4096 Aug 6 14:41 bin
-rw-r--r-- 1 root mysql 17987 Jan 7 2015 COPYING
drwxr-xr-x 3 root mysql 4096 Aug 6 14:41 data
drwxr-xr-x 2 root mysql 4096 Aug 6 14:41 docs
drwxr-xr-x 3 root mysql 4096 Aug 6 14:41 include
-rw-r--r-- 1 root mysql 147959 Jan 7 2015 INSTALL-BINARY
drwxr-xr-x 3 root mysql 4096 Aug 6 14:42 lib
drwxr-xr-x 4 root mysql 4096 Aug 6 14:41 man
drwxr-xr-x 10 root mysql 4096 Aug 6 14:42 mysql-test
-rw-r--r-- 1 root mysql 2496 Jan 7 2015 README
drwxr-xr-x 2 root mysql 4096 Aug 6 14:41 scripts
drwxr-xr-x 27 root mysql 4096 Aug 6 14:42 share
drwxr-xr-x 4 root mysql 4096 Aug 6 14:41 sql-bench
drwxr-xr-x 2 root mysql 4096 Aug 6 14:41 support-files
[root@bogon mysql]# ls support-files/
binary-configure config.small.ini my-innodb-heavy-4G.cnf my-small.cnf mysql.server
config.huge.ini magic my-large.cnf mysqld_multi.server ndb-config-2-node.ini
config.medium.ini my-huge.cnf my-medium.cnf mysql-log-rotate
#因为软件本身提供了,服务启动的脚本,我们这里直接复制并重命名即可;
[root@bogon mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@bogon mysql]# chkconfig --add mysqld
[root@bogon mysql]# chkconfig --list mysqld
mysqld
0:off
1:off
2:on
3:on
4:on
5:on
6:off
#提供配置文件,并且重命名为my.cnf
[root@bogon mysql]# cp support-files/my-large.cnf /etc/my.cnf
[root@bogon mysql]# vim /etc/my.cnf
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8
#添加我们更改的数据目录,只添加这一项;
datadir = /data/mydata
[root@bogon mysql]# service mysqld start
Starting MySQL....... SUCCESS!
#添加mysql命令,即创建文件告知内核的命令路径;
[root@bogon mysql]# vim /etc/profile.d/mysql.sh
#添加这一行即可
export PATH=/usr/local/mysql/bin:$PATH
#生效一下文件
[root@bogon mysql]# . /etc/profile.d/mysql.sh
[root@bogon mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.42-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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
[root@bogon mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql
`/usr/include/mysql' -> `/usr/local/mysql/include/'
[root@bogon mysql]# ls lib/
libmysqlclient.a libmysqlclient_r.so.18 libmysqlclient.so.18 libmysqld-debug.a plugin
libmysqlclient_r.a libmysqlclient_r.so.18.0.0 libmysqlclient.so.18.0.0 libmysqlservices.a
libmysqlclient_r.so libmysqlclient.so libmysqld.a libtcmalloc_minimal.so
[root@bogon mysql]# vim /etc/ld.so.conf.d/mysql.conf
#添加如下代码,表示添加库文件;
/usr/local/mysql/lib
[root@bogon mysql]# ldconfig -p | grep mysql
[root@bogon mysql]# ldconfig
[root@bogon mysql]# ldconfig -p | grep mysql
libtcmalloc_minimal.so.0 (libc6,x86-64) => /usr/local/mysql/lib/libtcmalloc_minimal.so.0
libmysqlclient.so.18 (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so.18
libmysqlclient.so (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so
[root@bogon mysql]# vim /etc/man.config
#然后我们就可以查看mysqld的man文档了
[root@bogon mysql]# man mysqld
从上面刚才,我们登录mysql时候,没有设置密码,直接登录。mysql的账号很独特,eg:
[email protected]
[root@bogon mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.42-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('mysql');
Query OK, 0 rows affected (0.06 sec)
mysql> SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('mysql');
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
[root@bogon mysql]# mysql -uroot -p -hlocalhost
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.42-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.10 sec)
mysql> use mysql;
Database changed
mysql> SHOW TABLES;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
24 rows in set (0.00 sec)
mysql> DESC user;
+------------------------+-----------------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+---------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(16) | NO | PRI | | |
| Password | char(41) | NO | | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
| Delete_priv | enum('N','Y') | NO | | N | |
| Create_priv | enum('N','Y') | NO | | N | |
| Drop_priv | enum('N','Y') | NO | | N | |
| Reload_priv | enum('N','Y') | NO | | N | |
| Shutdown_priv | enum('N','Y') | NO | | N | |
| Process_priv | enum('N','Y') | NO | | N | |
| File_priv | enum('N','Y') | NO | | N | |
| Grant_priv | enum('N','Y') | NO | | N | |
| References_priv | enum('N','Y') | NO | | N | |
| Index_priv | enum('N','Y') | NO | | N | |
| Alter_priv | enum('N','Y') | NO | | N | |
| Show_db_priv | enum('N','Y') | NO | | N | |
| Super_priv | enum('N','Y') | NO | | N | |
| Create_tmp_table_priv | enum('N','Y') | NO | | N | |
| Lock_tables_priv | enum('N','Y') | NO | | N | |
| Execute_priv | enum('N','Y') | NO | | N | |
| Repl_slave_priv | enum('N','Y') | NO | | N | |
| Repl_client_priv | enum('N','Y') | NO | | N | |
| Create_view_priv | enum('N','Y') | NO | | N | |
| Show_view_priv | enum('N','Y') | NO | | N | |
| Create_routine_priv | enum('N','Y') | NO | | N | |
| Alter_routine_priv | enum('N','Y') | NO | | N | |
| Create_user_priv | enum('N','Y') | NO | | N | |
| Event_priv | enum('N','Y') | NO | | N | |
| Trigger_priv | enum('N','Y') | NO | | N | |
| Create_tablespace_priv | enum('N','Y') | NO | | N | |
| ssl_type | enum('','ANY','X509','SPECIFIED') | NO | | | |
| ssl_cipher | blob | NO | | NULL | |
| x509_issuer | blob | NO | | NULL | |
| x509_subject | blob | NO | | NULL | |
| max_questions | int(11) unsigned | NO | | 0 | |
| max_updates | int(11) unsigned | NO | | 0 | |
| max_connections | int(11) unsigned | NO | | 0 | |
| max_user_connections | int(11) unsigned | NO | | 0 | |
| plugin | char(64) | YES | | | |
| authentication_string | text | YES | | NULL | |
+------------------------+-----------------------------------+------+-----+---------+-------+
42 rows in set (0.08 sec)
mysql> SELECT User,Host,Password FROM user;
+------+-----------+-------------------------------------------+
| User | Host | Password |
+------+-----------+-------------------------------------------+
| root | localhost | *E74858DB86EBA20BC33D0AECAE8A8108C56B17FA |
| root | bogon | |
| root | 127.0.0.1 | *E74858DB86EBA20BC33D0AECAE8A8108C56B17FA |
| root | ::1 | |
| | localhost | |
| | bogon | |
+------+-----------+-------------------------------------------+
6 rows in set (0.00 sec)
mysql> DROP USER 'root'@'::1';
Query OK, 0 rows affected (0.05 sec)
mysql> DROP USER 'root'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> DROP USER ''@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> DROP USER ''@'bogon';
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT User,Host,Password FROM user;
+------+-----------+-------------------------------------------+
| User | Host | Password |
+------+-----------+-------------------------------------------+
| root | bogon | |
| root | 127.0.0.1 | *E74858DB86EBA20BC33D0AECAE8A8108C56B17FA |
+------+-----------+-------------------------------------------+
2 rows in set (0.00 sec)
mysql> SET PASSWORD FOR 'root'@'bogon' = PASSWORD('mysql');
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT User,Host,Password FROM user;
+------+-----------+-------------------------------------------+
| User | Host | Password |
+------+-----------+-------------------------------------------+
| root | bogon | *E74858DB86EBA20BC33D0AECAE8A8108C56B17FA |
| root | 127.0.0.1 | *E74858DB86EBA20BC33D0AECAE8A8108C56B17FA |
+------+-----------+-------------------------------------------+
2 rows in set (0.00 sec)