linux下mysql的简单配置
linux下mysql的简单配置
罗荣熙 发表于3年前
linux下mysql的简单配置
  • 发表于 3年前
  • 阅读 95
  • 收藏 10
  • 点赞 0
  • 评论 1

腾讯云 技术升级10大核心产品年终让利>>>   

摘要: linux下mysql的简单配置

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;

恭喜你,到此为止,你再远程登陆就可以登陆成功了。

共有 人打赏支持
粉丝 26
博文 118
码字总数 84709
评论 (1)
betty小雅
老师:
您好!
我是源智天下有限公司的图书编辑,公司诚聘兼职作者,撰写开发方面的书籍,版权和署名都归作者所有,提升您的知名度和个人影响力,流程我们带你完成,你只要在一定的时间内完成一定的内容即可,感兴趣的话可以详谈:2917227785或者3174229616,期待与您的合作!
×
罗荣熙
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: