默認狀況下,數據已經初始化好,數據可參見默認配置文件/etc/my.cnfhtml
在其餘位置從新初始化MySQL數據庫:mysql
basedir是mysql的安裝根目錄,ldata是數據初始化的目錄web
mysql_install_db --basedir=/ --ldata=./datasql
相關提示:數據庫
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: 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_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 . ; mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com WARNING: 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 system This file will be read by default by the MySQL server If you do not want to use this, either remove it, or use the --defaults-file argument to mysqld_safe when starting the server
數據庫實例配置bootstrap
my.cnf配置文件內容less
# 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 log-error=/<your_dir>/log/mysql.log.err general_log = ON general_log_file=/<your_dir>/log/mysql_general.log slow_query_log = ON long_query_time=10 slow_query_log_file = /<your_dir>/log/mysql_slow_query.log # These are commonly set, remove the # and set as required. # basedir = ..... datadir=/<your_dir>/data port = 3306 # server_id = ..... socket = /<your_dir>/mysql.3306.sock pid-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=mysql sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
mysqld_safe --defaults-file=/<your_dir>/my.cnfsocket
mysql --socket=mysql.3306.sockide
查看數據庫狀態ui
mysqladmin --socket=mysql.3306.sock status
更改root密碼:
mysqladmin -u root password root --socket=mysql.3306.sock
數據庫關閉
mysqladmin -proot -uroot --socket=mysql.3306.sock shutdown
名爲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
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';
其中*.*表示對全部數據庫的全部表,這條語句能夠在建立用戶的同時給權限。
查看權限
SHOW GRANT
賦予權限
GRANT SELECT,UPDATE,DELETE ON *.* TO 'username'@'%'
收回權限
REVOKE ALL ON *.* TO 'username'@'%'
FLUSH PRIVILEGES
DROP USER 'username'@'%'
或者
DELETE FROM mysql.user WHERE Host = '%' AND User = 'username'
使用命令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")
發佈地址:www.cnblogs.com/qiusuo/p/9451717.html