百度智能云

All Product Document

          Relational Database Service

          Account Management

          Account Management

          Create an account

          Use the following codes to create a new account under a primary instance.

          // import "github.com/baidubce/bce-sdk-go/services/rds"
          
          args := &rds.CreateAccountArgs{
          	// account name, which cannot be a reserved keyword, required
              AccountName: "accountName",
              // password of account, consisting of letters, numbers or underscores, 6-32 digits
              Password: "password",
              // account privilege type, Common:common account, Super:super account. Common account by default, optional
              AccountType: "Common",
              // this item can be set in MySQL and SQL Server instances, optional
              DatabasePrivileges: []rds.DatabasePrivilege{
                      {
                          //database name
                          DbName: "user_photo_001",
                          //authorization type. ReadOnly:read only, ReadWrite:read and write
                          AuthType: "ReadOnly",
                      },   
                  },
              // account description information, optional
              Desc: "account user1", 
            // account attribution type, OnlyMaster: account used on primary instance, RdsProxy: account used on proxy instance corresponding to the primary instance. OnlyMaster account by default, optional
              Type: "OnlyMaster",
          }
          err = client.CreateAccount(instanceId, args)
          if err != nil {
              fmt.Printf("create account error: %+v\n", err)
              return
          }
          
          fmt.Println("create account success.")

          Note:

          • The status of instance is Available, and the instance must be a master instance.
          • Not exceed the maximum number of accounts under an instance.
          • If the database engine of the instance is PostgreSQL, only Super account can be created. The operations for other accounts and database are managed through this Super account.
          • If the database engine of the instance is MySQL, any type of account can be created.
          • If the database engine of the instance is SQLServer, only Common accounts can be created.

          Query account list

          Use the following codes to query the account list under specified instance.

          // import "github.com/baidubce/bce-sdk-go/services/rds"
          
          result, err := client.ListAccount(instanceId)
          if err != nil {
              fmt.Printf("list account error: %+v\n", err)
              return
          }
          
          // get the account list information
          for _, e := range result.Accounts {
              fmt.Println("rds accountName: ", e.AccountName)
              fmt.Println("rds desc: ", e.Desc)
              fmt.Println("rds status: ", e.Status)
              fmt.Println("rds type: ", e.Type)
              fmt.Println("rds accountType: ", e.AccountType)
          }

          Query specific account information

          Use the following codes to query specific account information.

          // import "github.com/baidubce/bce-sdk-go/services/rds"
          
          result, err := client.GetAccount(instanceId,accountName)
          if err != nil {
              fmt.Printf("get account error: %+v\n", err)
              return
          }
          
          // get account list information
          fmt.Println("rds accountName: ", result.AccountName)
          fmt.Println("rds desc: ", result.Desc)
          fmt.Println("rds status: ", result.Status)
          fmt.Println("rds type: ", result.Type)
          fmt.Println("rds accountType: ", result.AccountType)

          Delete specific account information

          Use the following codes to delete specific account information.

          // import "github.com/baidubce/bce-sdk-go/services/rds"
          
          result, err := client.DeleteAccount(instanceId,accountName)
          if err != nil {
              fmt.Printf("delete account error: %+v\n", err)
              return
          }
          fmt.Printf("delete account success\n")
          Previous
          Instance Management
          Next
          Parameter Management