注意一定要下对版本,好几次都失败在这上面。
[root@dell1 ~]# mkdir /home/soft/code_source_mysql/
[root@dell1 code_source_mysql]# tar -xzvf mysql-5.6.16.tar.gz
[root@dell1 code_source_mysql]# cd mysql-5.6.16
[root@dell1 mysql-5.6.16]# groupadd mysql
[root@dell1 mysql-5.6.16]# useradd -r -g mysql mysql
[root@dell1 mysql-5.6.16]# cmake .
[root@dell1 mysql-5.6.16]# make
[root@dell1 mysql-5.6.16]# make install
以上就完成了编译安装
[root@dell1 mysql-5.6.16]# cd /usr/local/mysql
[root@dell1 mysql]# ls
bin data include lib mysql-test scripts sql-bench
COPYING docs INSTALL-BINARY man README share support-files
[root@dell1 mysql]# chown -R mysql .
[root@dell1 mysql]# chgrp -R mysql .
[root@dell1 mysql]# scripts/mysql_install_db --user=mysql .................................................... 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 dell1 password 'new-password'
....................................................
mysql_install_db作用:
当MySQL的系统库(mysql系统库)发生故障或需要新加一个mysql实例时,需要初始化mysql数据库。
需要使用的命令:/usr/local/mysql/bin/mysql_install_db
#/usr/local/mysql/bin/mysql_install_db --he lp 可以查看帮助信息
[root@dell1 mysql]# chown -R root .
[root@dell1 mysql]# chown -R mysql data
[root@dell1 mysql]# cp support-files/mysql.server /etc/init.d/mysql
[root@dell1 mysql]# service mysql start
Starting MySQL SUCCESS!
[root@dell1 mysql]# chkconfig --add mysql [root@dell1 mysql]# chkconfig mysql on [root@dell1 mysql]# chkconfig list | grep mysql [root@dell1 mysql]# chkconfig --list | grep mysql mysql 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
完成
下面登录数据库
[root@dell1 mysql]# bin/mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
出现错误,是因为没有设置root账户的密码
[root@dell1 mysql]# bin/mysqladmin -u root password '034039'
[root@dell1 mysql]# bin/mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.6.16 Source distribution Copyright (c) 2000, 2014, 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>
登录成功
mysql> select version(); +-----------+ | version() | +-----------+ | 5.6.16 | +-----------+ 1 row in set (0.00 sec) mysql> status -------------- bin/mysql Ver 14.14 Distrib 5.6.16, for Linux (x86_64) using EditLine wrapper Connection id: 3 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.6.16 Source distribution Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: latin1 Db characterset: latin1 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /tmp/mysql.sock Uptime: 10 min 5 sec mysql> show variables like 'char%'; +--------------------------+----------------------------------+ | Variable_name | Value | +--------------------------+----------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/local/mysql/share/charsets/ | +--------------------------+----------------------------------+ 8 rows in set (0.00 sec)
配置文件的信息:mysql_install_db creates a default option file named my.cnf in the base installation directory. This
file is created from a template included in the distribution package named my-default.cnf.
[root@dell1 mysql]# ls
bin data include lib my.cnf README share support-files
COPYING docs INSTALL-BINARY man mysql-test scripts sql-bench
可以看到下面有my.cnf
[root@dell1 mysql]# vim my.cnf
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html [mysqld] # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. # basedir = ..... # datadir = ..... # port = ..... # server_id = ..... # socket = ..... # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES #以上就是my.cnf默认内容 #在以上文件中加入下面语句 [client] default-character-set=utf8 [mysql] default-character-set=utf8 [mysqld] character-set-server=utf8
保存退出
[root@dell1 mysql]# service mysql restart
Shutting down MySQL..140318 19:34:14 mysqld_safe mysqld from pid file /usr/local/mysql/data/dell1.pid ended
SUCCESS!
Starting MySQL. SUCCESS!
[1]+ Done bin/mysqld_safe --user=mysql
mysql> show variables like 'char%';
+--------------------------+----------------------------------+
| Variable_name | Value |
+--------------------------+----------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql/share/charsets/ |
+--------------------------+----------------------------------+
8 rows in set (0.00 sec)
完成
[root@dell1 mysql]# bin/mysql -h 192.168.0.105 -u root -p
Enter password:
ERROR 1130 (HY000): Host '192.168.0.105' is not allowed to connect to this MySQL server
从这里可以看出,需要授权
不然使用ip不能访问
mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select host ,user from user; +-----------+------+ | host | user | +-----------+------+ | 127.0.0.1 | root | | ::1 | root | | dell1 | | | dell1 | root | | localhost | | | localhost | root | +-----------+------+ 6 rows in set (0.00 sec)
从这里可以看出,root用户只能使用127.0.0.1或localhost登录
所以要对root用户进行授权,执行下面命令:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '034039' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec) mysql> select host ,user from user; +-----------+------+ | host | user | +-----------+------+ | % | root | | 127.0.0.1 | root | | ::1 | root | | dell1 | | | dell1 | root | | localhost | | | localhost | root | +-----------+------+ 7 rows in set (0.00 sec)
可以看到所有主机都可以使用root登录到数据库