七、设置MySQL配置文件
[root@node4 mysql5.5]# cp support-files/my-medium.cnf /etc/my.cnf //将mysql的启动服务添加到系统服务中 [root@node4 mysql5.5]# cp support-files/my-medium.cnf my.cnf [root@node4 mysql5.5]# more my.cnf ----在mysqld下面添加basedir = /opt/mysql5.5 datadir = /opt/mysql5.5/data [mysqld] port = 3306 socket = /tmp/mysql.sock skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M basedir = /opt/mysql5.5 datadir = /opt/mysql5.5/data
八、创建系统数据库的表
----在这里指定了配置文件和用户 [root@node4 mysql5.5]# scripts/mysql_install_db --defaults-file=./my.cnf --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: /opt/mysql5.5/bin/mysqladmin -u root password 'new-password' /opt/mysql5.5/bin/mysqladmin -u root -h node4 password 'new-password' Alternatively you can run: /opt/mysql5.5/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 /opt/mysql5.5 ; /opt/mysql5.5/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /opt/mysql5.5/mysql-test ; perl mysql-test-run.pl Please report any problems with the /opt/mysql5.5/scripts/mysqlbug script!
九、设置环境变量
[root@node4 ~]# vi /root/.bash_profile ----在PATH=$PATH:$HOME/bin添加参数为: PATH=$PATH:$HOME/bin:/opt/mysql5.5/bin:/opt/mysql5.5/lib [root@node4 ~]# source /root/.bash_profile
十、手动启动mysql
[root@node4 mysql5.5]# ./bin/mysqld_safe --user=mysql & //启动MySql但不能停止 [1] 27412 [root@node4 mysql5.5]# 130728 08:34:38 mysqld_safe Logging to '/opt/mysql5.5/data/node4.err'. 130728 08:34:38 mysqld_safe Starting mysqld daemon with databases from /opt/mysql5.5/data
----这里MYSQL��root用户还没有配置密码,所以空值。需要输入密码时,直接点回车键即可。 [root@node4 mysql5.5]# ./bin/mysqladmin -u root -p shutdown Enter password: 130728 08:34:46 mysqld_safe mysqld from pid file /opt/mysql5.5/data/node4.pid ended [1]+ Done ./bin/mysqld_safe --user=mysql
十一、另一个简单的启动mysql的方法(mysql已经被添加到系统服务中)
[root@node4 mysql5.5]# service mysql start [root@node4 mysql5.5]# service mysql stop [root@node4 mysql5.5]# service mysql restart
如果上述命令出现:mysql未识别的服务
[root@node4 mysql5.5]# service mysql start mysql.server: unrecognized service
则可能mysql还没添加到系统服务中,下面用另一个方法添加:
[root@node4 mysql5.5]# cp support-files/mysql.server /etc/init.d/mysql [root@node4 mysql5.5]# service mysql start Starting MySQL... [ OK ] [root@node4 mysql5.5]# service mysql stop Shutting down MySQL. [ OK ]
注意:主要是将mysql.server拷贝到/etc/init.d中,命名为mysql。然后再用#service mysql start 来启动mysql即可。
