1、安装默认的数据库
添加MySQL用户和用户组
[root@node1 ~]# groupadd mysql
[root@node1 ~]# useradd -g mysql mysql
进入安装目录,将程序二进制的所有权改为root,数据目录的说有权改为mysql用户,更新授权表
[root@node1 mysql-5.5.22]# cd /usr/local/mysql/
[root@node1 mysql]# chown -R root .
[root@node1 mysql]# chown -R mysql .
[root@node1 mysql]# chgrp -R mysql .
[root@node1 mysql]# scripts/mysql_install_db --user=mysql
2016-01-08 12:13:03 3745 [Note] Binlog end
2016-01-08 12:13:03 3745 [Note] InnoDB: FTS optimize thread exiting.
2016-01-08 12:13:03 3745 [Note] InnoDB: Starting shutdown...
2016-01-08 12:13:05 3745 [Note] InnoDB: Shutdown completed; log sequence number 1625987
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 node1 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/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as ./my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
安全启动MySQL(默认密码为空)
[root@localhost mysql]# ./bin/mysqld_safe --user=mysql&
source /etc/profile
报错:(有可能卡住,动弹不了)
120908 00:16:25 mysqld_safe Logging to '/usr/local/mysql/data/node1.err'.
120908 00:16:26 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
解决方法:
[root@node1 ~]# cd /usr/local/mysql/data
[root@node1 data]# ls
auto.cnf ib_logfile0 mysql node1.pid test
ibdata1 ib_logfile1 node1.err performance_schema
[root@node1 data]# chgrp -R mysql node1.err
[root@node1 data]# ls -l
total 110736
-rw-rw---- 1 mysql mysql 56 Jan 8 12:15 auto.cnf
-rw-rw---- 1 mysql mysql 12582912 Jan 8 12:15 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Jan 8 12:15 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Jan 8 12:12 ib_logfile1
drwx------ 2 mysql mysql 4096 Jan 8 12:13 mysql
-rw-r----- 1 mysql mysql 2055 Jan 8 12:16 node1.err
-rw-rw---- 1 mysql mysql 5 Jan 8 12:15 node1.pid
drwx------ 2 mysql mysql 4096 Jan 8 12:13 performance_schema
drwxr-xr-x 2 mysql mysql 4096 Jan 7 20:42 test
2、配置用户,环境变量
MySQL启动成功后,root默认没有密码,我们需要设置root密码。
设置之前,我们需要先设置PATH,要不不能直接调用mysql
修改bash_profile文件,在文件末尾添加
[root@node1 ~]# vi .bash_profile
复制代码代码如下:
PATH=/usr/local/mysql/bin:$PATH
export PATH
关闭文件,运行下面的命令,让配置立即生效
复制代码代码如下:
[root@node1 root]# source .bash_profile
连接本机MySQL
[root@node1 mysql]#mysql –u root –p
提示输入password,默认为空,按Enter即可
[root@node1 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.28 Source distribution
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.59 sec)
断开连接
mysql>exit;
为root账户设置密码
[root@node1 mysql]# mysqladmin -u root password 123456
设置选项文件,将配置文件拷贝到/etc下
[root@node1 mysql]# cp support-files/my-medium.cnf /etc/mysql.cnf
设置开机自启动
[root@node1 mysql]# cp support-files/mysql.server /etc/init.d/mysql
[root@node1 mysql]# chmod +x /etc/init.d/mysql
[root@node1 mysql]# chkconfig mysql on
3.安装设置完毕,之后使用只需启动-连接-断开-关闭,命令如下:
通过服务来启动和关闭Mysql
[root@node1 mysql]# service mysql start
Starting MySQL.. [确定]
[root@CentOS mysql]# service mysql stop
Shutting down MySQL. [确定]
4.其它:
查看进程命令 ps –ef|grep mysqld
kill进程命令 kill –9 进程号