MYSQL 啓動:html
mysqld, also known as MySQL Server, is the main program that does most of the work in a MySQL installation. MySQL Server manages access to the MySQL data directory that contains databases and tables. The data directory is also the default location for other information such as log files and status files.mysql
When MySQL server starts, it listens for network connections from client programs and manages access to databases on behalf of those clients.sql
The mysqld program has many options that can be specified at startup. For a complete list of options, run this command:shell
shell> mysqld --verbose --help
mysqld_safe is the recommended way to start a mysqld server on Unix. mysqld_safe adds some safety features such as restarting the server when an error occurs and logging runtime information to an error log file. A description of error logging is given later in this section.數據庫
mysqld_safe Options服務器
Format | Description | Introduced |
---|---|---|
--basedir | Path to MySQL installation directory | |
--core-file-size | Size of core file that mysqld should be able to create | |
--datadir | Path to data directory | |
--defaults-extra-file | Read named option file in addition to usual option files | |
--defaults-file | Read only named option file | |
--help | Display help message and exit | |
--ledir | Path to directory where server is located | |
--log-error | Write error log to named file | |
--malloc-lib | Alternative malloc library to use for mysqld | |
--mysqld | Name of server program to start (in ledir directory) | |
--mysqld-safe-log-timestamps | Timestamp format for logging | 5.7.11 |
--mysqld-version | Suffix for server program name | |
--nice | Use nice program to set server scheduling priority | |
--no-defaults | Read no option files | |
--open-files-limit | Number of files that mysqld should be able to open | |
--pid-file | Path name of process ID file | |
--plugin-dir | Directory where plugins are installed | |
--port | Port number on which to listen for TCP/IP connections | |
--skip-kill-mysqld | Do not try to kill stray mysqld processes | |
--skip-syslog | Do not write error messages to syslog; use error log file | |
--socket | Socket file on which to listen for Unix socket connections | |
--syslog | Write error messages to syslog | |
--syslog-tag | Tag suffix for messages written to syslog | |
--timezone | Set TZ time zone environment variable to named value | |
--user | Run mysqld as user having name user_name or numeric user ID user_id |
/home/mypath/mysql/bin/mysqld_safe --defaults-file=/home/mypath/mysql/etc/my.cnfsocket
/home/mypath/mysql/bin/mysqld --defaults-file=/home/mypath/mysql/etc/my.cnf --basedir=/home/my/mysql --datadir=/home/mypath/mysql/data --plugin-dir=/home/mypath /mysql/lib/plugin --log-error=/home/mypath/mysql/log/mysql.err --pid-file=/home/mypath/mysql/tmp/mysql.pid --socket=/home/mypath/mysql/tmp/mysql.sock --port=3377sqlserver
Unix系統下本地鏈接MySQL能夠採用Unix域套接字方式,mysql.sock文件是服務器與本地客戶端進行通訊的Unix套接字文件,程序與mysqlserver處於同一臺機器,發起本地鏈接時可用。該文件由參數socket指定ui
mysql>show variables like 'socket'\G;this
當MySQL實例啓動時,會將本身的進程ID寫入一個文件中—該文件即爲pid文件。該文件可由參數pid_file控制
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'db'
You may need to set up a root account for your MySQL database: In the terminal type: mysqladmin -u root password 'root' And then to invoke the MySQL client: mysql -h localhost -u root -p |
新建用戶提示錯誤:
insert into mysql.user(Host,User,Password) values("localhost","test",password("1234"));
Field 'ssl_cipher' doesn't have a default value
那麼就不用insert了,換種方法:
GRANT USAGE ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
「username」替換爲將要受權的用戶名,好比clientusr;
「password」替換爲clientusr設置的密碼;
locaohost能夠改成%,方便你從別的IP登陸。
而後對你建的用戶進行受權
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON database.* TO 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mima' WITH GRANT OPTION; //對全部ip受權
本語句中的權限根據實際須要肯定:
"tablename"替換爲受權訪問的數據表table名
"username"是步驟2受權用戶名
"password"是步驟2受權用戶的設置密碼
這樣就爲該用戶授予了對某數據表的SELECT, INSERT, UPDATE, DELETE, CAREATE, DROP權限。
四、生效受權,建立完畢
一句話便可:FLUSH PRIVILEGES;
特別提醒注意的一點是,新版(5.7)的mysql數據庫下的user表中已經沒有Password字段了
而是將加密後的用戶密碼存儲於authentication_string字段
> flush privileges; 更新權限
> quit 退出
service mysqld restart
mysql -uroot -p新密碼進入
(1)使用mysqld_safe &啓動
(1)因機器內存不足致使啓動失敗,將配置文件 etc/my.cnf 使用mysql-small.cnf (小內存)配置
或直接加以下配置至 my.cnf
key_buffer=16K
table_open_cache=4
query_cache_limit=256K
query_cache_size=4M
max_allowed_packet=1M
sort_buffer_size=64K
read_buffer_size=256K
thread_stack=64K
innodb_buffer_pool_size = 56M
You may need to set up a root account for your MySQL database:
In the terminal type:
mysqladmin -u root password 'root password goes here'
And then to invoke the MySQL client:
mysql -h localhost -u root -p