1、设置字符编码
输入命令:
[root@localhost ~]# vi /etc/my.cnf
最后一行加入:default-character-set=utf8,保存!
2、启动mysql服务:
输入命令:
[root@localhost ~]# service mysqld start
返回一下信息则表示已经启动成功
Initializing MySQL database: 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:
/usr/bin/mysqladmin -u root password ‘new-password‘
/usr/bin/mysqladmin -u root -h localhost.localdomain password ‘new-password‘
Alternatively you can run:
/usr/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 ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
[ OK ]
Starting mysqld: [ OK ]
3、设置开机启动:
输入命令:
[root@localhost ~]# chkconfig –add mysqld
[root@localhost ~]# chkconfig mysqld on
4、查看开机启动设置是否成功
输入命令:
[root@localhost ~]# chkconfig –list | grep mysql mysqld
返回一下信息则表示已经设置成功
grep: mysqld: No such file or directory
[root@localhost ~]# chkconfig –list | grep mysql
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
5、创建root管理员:
输入命令:(设置用户名为root,密码为123456)
[root@localhost ~]# mysqladmin -u root password 123456
6、登录数据库:
输入命令:
[root@localhost ~]# 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.1.73 Source distribution
Copyright (c) 2000, 2013, 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>
7、如果是你的mysql数据库是虚拟机linux端安装的,可能会遇到远程访问不了的问题,解决方案如下:
(1)修改防火墙,开启3306端口。
输入命令:
[root@localhost ~]# vi /etc/sysconfig/iptables
添加一行:
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
(2)重启服务
输入命令:
[root@localhost ~]# service iptables restart
返回信息:
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
(3)授权用户从远程登录
具体步骤:登陆到mysql
首先 use mysql;
mysql> update user set host=‘%‘ where user = ‘root‘;
返回信息:
ERROR 1062 (23000): Duplicate entry ‘%-root‘ for key ‘PRIMARY‘
然后查看了下数据库的host信息如下:
mysql> select host from user where user = ‘root‘;
+———————–+
| host |
+———————–+
| % |
| 127.0.0.1 |
| localhost.localdomain |
+———————–+
3 rows in set (0.00 sec)
host已经有了%这个值,所以直接运行命令:
mysql>flush privileges;
恭喜你,导致为止,你再远程登陆就可以登陆成功了。