当前位置:首页 » 《随便一记》 » 正文

Linux 安装Mysql 常见错误及总结

17 人参与  2022年07月20日 08:41  分类 : 《随便一记》  评论

点击全文阅读


1,安装的方法菜鸟教程上有:入口

mysqld --initialize#命令是出现如下错误Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!

2,数据库初始化

默认情况下,数据已经初始化好,数据可参见默认配置文件/etc/my.cnf

在其他位置重新初始化MySQL数据库:

basedir是mysql的安装根目录,ldata是数据初始化的目录

mysql_install_db --basedir=/ --ldata=./data

相关提示:

To start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands:  mysqladmin -u root password 'new-password'  mysqladmin -u root -h gzns-map-tc-spd-server-shanghai00.gzns.baidu.com password 'new-password'Alternatively you can run:  mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default.  This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:  cd . ; mysqld_safe &You can test the MySQL daemon with mysql-test-run.pl  cd mysql-test ; perl mysql-test-run.plPlease report any problems at http://bugs.mysql.com/The latest information about MySQL is available on the web at  http://www.mysql.comSupport MySQL by buying support/licenses at http://shop.mysql.comWARNING: Found existing config file /etc/my.cnf on the system.Because this file might be in use, it was not replaced,but was used in bootstrap (unless you used --defaults-file)and when you later start the server.The new default config file was created as /etc/my-new.cnf,please compare it with your file and take the changes you need.WARNING: Default config file /etc/my.cnf exists on the systemThis file will be read by default by the MySQL serverIf you do not want to use this, either remove it, or use the--defaults-file argument to mysqld_safe when starting the server

数据库实例配置

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_binlog-error=/<your_dir>/log/mysql.log.errgeneral_log = ONgeneral_log_file=/<your_dir>/log/mysql_general.logslow_query_log = ONlong_query_time=10slow_query_log_file = /<your_dir>/log/mysql_slow_query.log# These are commonly set, remove the # and set as required.# basedir = .....datadir=/<your_dir>/dataport = 3306# server_id = .....socket = /<your_dir>/mysql.3306.sockpid-file =/<your_dir>/mysql.3306.pid# 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 user=mysqlsql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

3,数据库启动

mysqld_safe --defaults-file=/<your_dir>/my.cnf

4,数据库登录

mysql --socket=mysql.3306.sock

5,数据库实例管理

查看数据库状态mysqladmin --socket=mysql.3306.sock status更改root密码:mysqladmin -u root password root --socket=mysql.3306.sock数据库关闭mysqladmin -proot -uroot --socket=mysql.3306.sock shutdown

6,用户和权限管理

名为mysql的数据库中存放这元数据,其中use表与用户和权限有关。use表的Host User Password列与用户登录有关,这三列可以确定登录用户的身份。use表的Select_priv、Insert_priv等以priv结尾的列与用户权限有关,Y表示对所有表生效,N表示不对所有表生效。使用数据库root用户登录数据库,并使用mysql数据库mysql -uroot -proot --socket=mysql.3306.sock -D mysql

(1),新建普通用户

create user 'username'@'host' identified by 'password'其中host可以由%代替,表示对所有host登录的都适用。或者INSERT INTO mysql.user(Host,User,Password,ssl_cipher,x509_issuer,x509_subject) VALUES('%','username',PASSWORD('password'),'','','');FLUSH PRIVILEGES或者GRANT SELECT ON *.* TO 'username'@'%' identified by 'password';其中*.*表示对所有数据库的所有表,这条语句可以在创建用户的同时给权限。

(2),用户权限

查看权限

SHOW GRANT

赋予权限

GRANT SELECT,UPDATE,DELETE ON *.* TO 'username'@'%'

收回权限

REVOKE ALL ON *.* TO 'username'@'%' 

FLUSH PRIVILEGES

(3),删除用户

DROP USER 'username'@'%'

或者

DELETE FROM mysql.user WHERE Host = '%' AND User = 'username'

(4),修改密码

使用命令mysqladmin -u -username -p password "new_password"

或者改表

UPDATE user SET Password = PASSWORD('new_password') WHERE USER = 'username' and Host = '%'

FLUSH PRIVILEGES

或者修改当前用户密码

SET PASSWORD = PASSWORD("new_password");

修改其他用户密码

SET PASSWORD FOR 'username'@'%'=PASSWORD("new_password")

7,配置mysql 远程登录的方法

默认情况下,mysql只允许本地登录,如果要开启远程连接,则需要修改/etc/mysql/my.conf文件。

(1),修改/etc/mysql/my.conf
找到bind-address = 127.0.0.1这一行
改为bind-address = 0.0.0.0即可

(2),为需要远程登录的用户赋予权限
        1、新建用户远程连接mysql数据库
grant all on *.* to root@'%' identified by 'root' with grant option; 
flush privileges;
允许任何ip地址(%表示允许任何ip地址)的电脑用root帐户和密码(root)来访问这个mysql server。
注意root账户不一定要存在。

        2、支持root用户允许远程连接mysql数据库
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;


点击全文阅读


本文链接:http://m.zhangshiyu.com/post/43537.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1